一、cxf 生成 webservice 客户端

1、接口路径 http://ws.webxml.com.cn/WebServices/WeatherWS.asmx

2、进入你需要放置 webservice 客户端代码的包,进入这个包所在的系统路径,进入 cmd

3、执行命令 wsimport -keep http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl 或者 wsdl2java -client http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl

  3.1、如果报错信息如下:具有相同名称“xxx”的类/接口已经使用。

  wsdl2java -client http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl

  改为

  wsdl2java -client -autoNameResolution http://ws.webxml.com.cn/WebServices/WeatherWS.asmx?wsdl

4、spring 整合 cxf

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jaxws="http://cxf.apache.org/jaxws" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<jaxws:client id="userClient"
serviceClass="com.java.webservice.service.impl.ITianQi" <!--生成的接口-->
address="http://ws.webxml.com.cn/WebServices/WeatherWS.asmx">
</jaxws:client>
</beans>

二、httpclient 调用 webservice

public static String getXML() {
StringBuffer sb = new StringBuffer();
sb.append("<?xml version='1.0' encoding='utf-8'?>"
+ "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>"
+ "<soap:Body>" + "<getMobileCodeInfo xmlns='http://WebXml.com.cn/'>"
+ "<mobileCode>string</mobileCode>" + " <userID>string</userID>" + "</getMobileCodeInfo>"
+ "</soap:Body>" + "</soap:Envelope>");
return sb.toString();
}
static int socketTimeout = 30000;// 请求超时时间
static int connectTimeout = 30000;// 传输超时时间 public static String doPost() {
String postUrl = "http://ws.webxml.com.cn/WebServices/WeatherWS.asmx";
String soapAction = "";
String soapXml = getXML();
String retStr = "";
// 创建HttpClientBuilder
HttpClientBuilder httpClientBuilder = HttpClientBuilder.create();
// HttpClient
CloseableHttpClient closeableHttpClient = httpClientBuilder.build();
HttpPost httpPost = new HttpPost(postUrl);
// 设置请求和传输超时时间
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(socketTimeout)
.setConnectTimeout(connectTimeout).build();
httpPost.setConfig(requestConfig);
try {
httpPost.setHeader("Content-Type", "application/soap+xml;charset=UTF-8");
httpPost.setHeader("SOAPAction", soapAction);
StringEntity data = new StringEntity(soapXml, Charset.forName("UTF-8"));
httpPost.setEntity(data);
CloseableHttpResponse response = closeableHttpClient.execute(httpPost);
HttpEntity httpEntity = response.getEntity();
if (httpEntity != null) {
// 打印响应内容
retStr = EntityUtils.toString(httpEntity, "UTF-8");
}
// 释放资源
closeableHttpClient.close();
} catch (Exception e) {
}
return retStr;
}

cxf 和 httpclient 客户端调用 webservice 接口的更多相关文章

  1. So easy Webservice 3.使用HttpClient工具调用Webservice接口

    首先,看看webservice服务调用演示: a) 登录http://www.webxml.com.cn b) 单击手机查询服务 c) 选择要调用的方法 例如: getMobileCodeInfo 输 ...

  2. WebService:CXF的JaxWsDynamicClientFactory实现调用WebService接口

    首先需要引入依赖jar包 #版本只供参考,具体看项目 <dependency> <grouId>org.apache.cxf</grouId> <artifa ...

  3. Java之HttpClient调用WebService接口发送短信源码实战

    摘要 Java之HttpClient调用WebService接口发送短信源码实战 一:接口文档 二:WSDL 三:HttpClient方法 HttpClient方法一 HttpClient方法二 Ht ...

  4. Java调用webservice接口方法

                             java调用webservice接口   webservice的 发布一般都是使用WSDL(web service descriptive langu ...

  5. php中创建和调用webservice接口示例

    php中创建和调用webservice接口示例   这篇文章主要介绍了php中创建和调用webservice接口示例,包括webservice基本知识.webservice服务端例子.webservi ...

  6. java 调用webservice接口wsdl,推荐使用wsdl2java,放弃wsimport

    网上说wsimport是jdk1.6后自带的客户端生成调用webservice接口的工具,其实我挺喜欢原生的东西,毕竟自家的东西用着应该最顺手啊,但往往让人惊艳的是那些集成工具. 本机jdk1.8.1 ...

  7. ThinkPHP使用soapclient调用webservice接口

    1,开启 php.ini 这2个服务 12 extension=php_openssl.dllextension=php_soap.dll 以公共天气预报webservice为例,采用thinkPHP ...

  8. 使用soapui调用webservice接口

    soapui是专门模拟调用webservice接口的工具,下面介绍下怎么使用: 1.下载soapui并安装: 2.以免费天气获取接口为例:http://www.webservicex.net/glob ...

  9. 使用JS调用WebService接口

    <script> $(document).ready(function () { var username = "admin"; var password = &quo ...

随机推荐

  1. 【Apio2009】Bzoj1179 Atm

    目录 List Description Input Output Sample Input Sample Output HINT Solution Code Dfs 记忆化搜索 Position: h ...

  2. codeforces round #414 div1+div2

    A:判断一下就可以了 #include<bits/stdc++.h> using namespace std; typedef long long ll; int a, b, c, n; ...

  3. codevs3287货车运输(最小生成树+LCA)

    3287 货车运输 2013年NOIP全国联赛提高组  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond     题目描述 Description A 国有 ...

  4. .net C# 格式化时间

    1.HtmlEncode="False" 2.DataFormatString="{0:d}" C#格式化日期时间 DateTime dt = DateTime ...

  5. cocos creator学习

    2019-05-30 22:23:27 按照前一节我发的教程做,大概了解了Cocos creator的基本布局 但是你发现你不好写代码(感觉视频没有提) 需要下载VS code软件,在其上进行编辑,教 ...

  6. HTML--文本域,支持多行文本输入

    当用户需要在表单中输入大段文字时,需要用到文本输入域. 语法: <textarea rows="行数" cols="列数">文本</texta ...

  7. gerrit项目配置

    1. 相关约定说明: 1.1 gerrit服务器ip地址:192.168.130.10 1.2 gerrit服务器端用户名:gerrit 1.3 gerrit用户端管理员:admin 1.4 ssh端 ...

  8. hcode视频教程中心(学习h5和hbuilder等)

    网站: http://www.hcoder.net/course

  9. 数字签名与数字证书以及https

    数字签名与数字证书以及httpshttps://blog.csdn.net/lzghxjt/article/details/79604602

  10. C#——设置开机启动

    将exe应用程序设置为开机启动,有多种方法,我们主要通过注册表设置开机启动选项. using Microsoft.Win32; using System.Windows.Forms; static v ...