一种基于http协议使用WebService方法

首先我们先下载一个叫SoapUI的软件 (直接百度)

安装这个就不用多说。

使用:

  1.创建一个SOAP project

  webService 使用 httpClient httpCore 学习_第1张图片


  填入WSDL

 webService 使用 httpClient httpCore 学习_第2张图片

然后会解析出来一些数据。找到我们想要对接的接口 比如我对接的方法是

webService 使用 httpClient httpCore 学习_第3张图片

双击打开是:

   

   

     

         

         ?

         

         ?

         

         ?

         

         ?

     

   


以及 

webService 使用 httpClient httpCore 学习_第4张图片



这个就是我们即将需要的。


Java代码

public void SendLianbiWebService()throws ParseException, IOException {

HttpClient client = HttpClients.createDefault();

String reqSoapData = buildReqSoapData(liBiEntity);//此处就是拼接SOAP请求

HttpPost post = new HttpPost(WSDLURL);// WSDLURL 就是提供的WSDL

try {

HttpEntity re = new StringEntity(reqSoapData, "UTF-8");

post.setHeader("Content-Type", "text/xml;charset=UTF-8");

post.setHeader("Accept-Encoding", "gzip,deflate");

post.setHeader("SOAPAction","http://tempuri.org/IWarehouse_Business/update_change_Lianbi_info");

post.setEntity(re);

response = client.execute(post);//发送请求

returnInfo = EntityUtils.toString(response.getEntity());

log.info("请求服务返回XML文本:" + returnInfo);

} catch (UnsupportedEncodingException e) {

log.error(e.getStackTrace());

} catch (ClientProtocolException e) {

log.error(e.getStackTrace());

} catch (IOException e) {

log.error(e.getStackTrace());

}


下面介绍