美文网首页
WebService请求的几种方式

WebService请求的几种方式

作者: 你笑时很美丶 | 来源:发表于2018-10-30 10:01 被阅读0次

一、eclipse工具生成wsdl文件请求:

next-finish可以自己选择路径,会生成

接下来就可以直接调用了(可以看到引用了soapPort类,里面有你接口的方法,直接调用就好了)

WDATALBServicesLocator servince = new WDATALBServicesLocator(); WCdataReaderServiceSoapPort client = servince.getWCdataReaderServiceSoapPort(); String loginXml = client.WCDataNetReaderLogin("<RLoginName>" + certId + "</RLoginName><RPassword>" + password + "</RPassword>");

二、通过axis请求:

先引入org.apache.axis包,https://mvnrepository.com/artifact/org.apache.axis/axis/1.4

这是工具类

import org.apache.axis.client.Call;

import org.apache.axis.client.Service;

public class axis {

    public static String axis1(String user, String password) {

        Object ret = null;

        try {

            //调用webservice地址     

            String url = "xxxxxxxxx?wsdl";

            //调用方法名

            String method = "xxxxxxx";

            Service service = new Service();

            //通过service创建call对象   

            Call call = (Call) service.createCall();

            //设置服务地址

            call.setTargetEndpointAddress(new java.net.URL(url));

            //设置调用方法

            call.setOperationName(method);

            call.setUseSOAPAction(true);

            //添加方法的参数,有几个添加几个

            //inLicense是参数名,XSD_STRING是参数类型,IN代表传入

            call.addParameter("参数名",org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);

            call.addParameter("参数名", org.apache.axis.encoding.XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);

            //设置返回类型 

            call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);

            try {

                //使用invoke调用方法,Object数据放传入的参数值

                ret = call.invoke(new Object[] { user, password });

            } catch (Exception e) {

                e.printStackTrace();

            }

            //输出返回信息

            System.out.println("result===" + ret.toString());

        } catch (Exception e) {

            e.printStackTrace();

        }

        return ret.toString();

    }

}

相关文章

网友评论

      本文标题:WebService请求的几种方式

      本文链接:https://www.haomeiwen.com/subject/kqpwtqtx.html