WebService客户端几种实现方式

编程入门 行业动态 更新时间:2024-10-11 13:24:19

WebService客户端<a href=https://www.elefans.com/category/jswz/34/1769370.html style=几种实现方式"/>

WebService客户端几种实现方式

客户端几种实现方式(转载)

Demo-HttpClient

  public static void main(String[] args) throws Exception {//soap服务地址String url = "http://10.104.168.38:6906/sip/services/XJSSServices?wsdl";StringBuilder soapBuilder = new StringBuilder(64);soapBuilder.append("<soapenv:Envelope xmlns:soapenv=\"/\" xmlns:xj=\"\">");soapBuilder.append("   <soapenv:Header/>");soapBuilder.append("       <soapenv:Body>");soapBuilder.append("             <xj:QuerySwGxxx>");soapBuilder.append("                   <xj:bwlx>CBXX001</xj:bwlx>");soapBuilder.append("               <xj:bw></xj:bw>");soapBuilder.append("               </xj:QuerySwGxxx>");soapBuilder.append("    </soapenv:Body>");soapBuilder.append("</soapenv:Envelope>");//创建httpcleint对象CloseableHttpClient httpClient = HttpClients.createDefault();//创建http Post请求HttpPost httpPost = new HttpPost(url);// 构建请求配置信息RequestConfig config = RequestConfig.custom().setConnectTimeout(1000) // 创建连接的最长时间.setConnectionRequestTimeout(500) // 从连接池中获取到连接的最长时间.setSocketTimeout(3 * 1000) // 数据传输的最长时间10s.build();httpPost.setConfig(config);CloseableHttpResponse response = null;try {//采用SOAP1.1调用服务端,这种方式能调用服务端为soap1.1和soap1.2的服务httpPost.setHeader("Content-Type", "text/xml;charset=UTF-8");httpPost.setHeader("SOAPAction", "http://10.104.168.38:6906/sip/services/XJSSServices?wsdl");//采用SOAP1.2调用服务端,这种方式只能调用服务端为soap1.2的服务StringEntity stringEntity = new StringEntity(soapBuilder.toString(), Charset.forName("UTF-8"));httpPost.setEntity(stringEntity);response = httpClient.execute(httpPost);// 判断返回状态是否为200if (response.getStatusLine().getStatusCode() == 200) {String content = EntityUtils.toString(response.getEntity(), "UTF-8");System.out.println("------------:"+content);} else {System.out.println("调用失败!");}} catch (Exception e) {e.printStackTrace();} finally {if (null != response) {response.close();}if (null != httpClient) {httpClient.close();}}}

更多推荐

WebService客户端几种实现方式

本文发布于:2023-11-16 17:58:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629551.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:几种   客户端   方式   WebService

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!