Keep Running

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

java RPC方式调用axis2 webservice

  1. 所需jar包包括:
    import javax.xml.namespace.QName;
    import javax.xml.rpc.ServiceException;
    import org.apache.axis2.AxisFault;
    import org.apache.axis2.addressing.EndpointReference;
    import org.apache.axis2.client.Options;
    import org.apache.axis2.rpc.client.RPCServiceClient;

    除了引入的这些jar包之外,还需要axis2 下的commons-httpclient-3.1.jar包,通过该包进行webservice通信。

  2. 调用axis2服务和调用wcf服务不同,所需要传入的参数包括,webservice地址,方法名,方法参数,webservice命名空间,和返回类型,其中方法参数是一个Object数组,参数类型根据Object数组决定。源码如下:
    private static  RPCServiceClient serviceClient;
        /**
         * RPC调用AXIS2 webservice
         * @param endpoint 服务地址 如:http://192.168.0.1:2597/aixs2/services/jqservice?wsdl
         * @param localPart 方法名 如<xs:element name="Receive">
         * @param opArgs 方法参数 如Object[] opArgs = new Object[] { param }; 
         * @param namespaceURI 命名空间 如 :targetNamespace="http://server.test.com.cn">
         * @param opReturnType 返回类型 如字符串:Class[] opReturnType = new Class[] { String[].class };
         */
        public static String axis2RPCInvoke(String endpoint,String localPart,Object[] opArgs,String namespaceURI,Class[] opReturnType)
        {
            Object[] ret = null;
            try
            {
                serviceClient = new RPCServiceClient();
                Options options = serviceClient.getOptions();
                EndpointReference targetEPR = new EndpointReference(endpoint);
                options.setTo(targetEPR);
                QName opQName = new QName(namespaceURI, localPart);
                ret = serviceClient.invokeBlocking(opQName, opArgs, opReturnType);
                System.out.println(((String[]) ret[0])[0]);
            }
            catch (AxisFault e)
            {
                e.printStackTrace();
            }
            return ((String[]) ret[0])[0];
        }

     

  3. 测试方法如下:
    public static void main(String[] args)
        {
            axis2RPCInvoke("http://172.16.5.22:9090/axis2/services/MyService?wsdl", "Receive", new Object[] {"122"}, "http://lincb.com",  new Class[] { String[].class });
        }

     

posted on   Keep Running  阅读(12845)  评论(2编辑  收藏  举报

编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· SQL Server 2025 AI相关能力初探
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示