Java调用WebService接口的方法

这篇文章主要介绍了Java调用WebService接口的方法,实例分析了有参方法Add的使用技巧,需要的朋友可以参考下

本文实例讲述了Java调用WebService接口的方法。分享给大家供大家参考。具体如下:

这里讲述有参方法Add,代码如下:

复制代码 代码如下:
public static void addTest() {
        try ...{
            Integer i = 1;
            Integer j = 2;
           
            //WebService URL
            String service_url = "http://localhost:4079/ws/Service.asmx";
           
            Service service = new Service();
            Call call = (Call) service.createCall();
            call.setTargetEndpointAddress(new java.net.URL(service_url));
           
            //设置要调用的方法
            call.setOperationName(new QName("https://www.0133.cn/T", "Add"));
           
            //该方法需要的参数
            call.addParameter("a", org.apache.axis.encoding.XMLType.XSD_INT,
                    javax.xml.rpc.ParameterMode.IN);
            call.addParameter("b", org.apache.axis.encoding.XMLType.XSD_INT,
                    javax.xml.rpc.ParameterMode.IN);
           
            //方法的返回值类型
            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_INT);
           
            call.setUseSOAPAction(true);
            call.setSOAPActionURI("https://www.0133.cn/Add");
           
            //调用该方法
            Integer res = (Integer)call.invoke(
                    new Object[]...{
                        i, j
                    }
            );
           
            System.out.println( "Result: " + res.toString());
           
        } catch (Exception e) ...{
            System.err.println(e);
        }
}

运行,结果返回:Result:3

希望本文所述对大家的Java程序设计有所帮助。

以上就是Java调用WebService接口的方法的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » Java