WSDL文件:http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl
?
CXF 提供了将WSDL文件生成的java的工具,wsdl2java.bat。要想使用首先将CXF配置到系统环境变量中,在这里就不具体配置啦!
?
wsdl2java用法:
wsdl2java -p com -d src -all? aa.wsdl
-p? 指定其wsdl的命名空间,也就是要生成代码的包名
-d? 指定要产生代码所在目录
-client 生成客户端测试web service的代码
-server 生成服务器启动web service的代码
-impl 生成web service的实现代码
-ant? 生成build.xml文件
-all 生成所有开始端点代码:types,service proxy,,service interface, server mainline, client mainline, implementation object, and an Ant build.xml file.
详细用法见:http://cwiki.apache.org/CXF20DOC/wsdl-to-java.html
?
先看看wsdl文件
?????
<?xml version="1.0" encoding="utf-8"?> <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://WebXml.com.cn/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="http://WebXml.com.cn/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><a href="http://www.webxml.com.cn/" target="_blank">WebXml.com.cn</a> <strong>IP地址搜索 WEB 服务</strong>包含中国和国外已知的IP地址数据,是目前最完整的IP地址数据,记录数量现已超过37万条并还在不断更新和增加中,因IP地址在不断变化,此IP地址数据查询仅供参考。</br>此IP地址搜索Web Services请不要用于任何商业目的,若有需要请<a href="http://www.webxml.com.cn/zh_cn/contact_us.aspx" target="_blank">联系我们</a>,欢迎技术交流。 QQ:8409035<br /><strong>使用本站 WEB 服务请注明或链接本站:http://www.webxml.com.cn/ 感谢大家的支持</strong>!<br /><br />&nbsp;</wsdl:documentation> <wsdl:types> <s:schema elementFormDefault="qualified" targetNamespace="http://WebXml.com.cn/"> <s:element name="getCountryCityByIp"> <s:complexType> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="theIpAddress" type="s:string" /> </s:sequence> </s:complexType> </s:element> <s:element name="getCountryCityByIpResponse"> <s:complexType> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="getCountryCityByIpResult" type="tns:ArrayOfString" /> </s:sequence> </s:complexType> </s:element> <s:complexType name="ArrayOfString"> <s:sequence> <s:element minOccurs="0" maxOccurs="unbounded" name="string" nillable="true" type="s:string" /> </s:sequence> </s:complexType> <s:element name="getGeoIPContext"> <s:complexType /> </s:element> <s:element name="getGeoIPContextResponse"> <s:complexType> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="getGeoIPContextResult" type="tns:ArrayOfString" /> </s:sequence> </s:complexType> </s:element> <s:element name="getVersionTime"> <s:complexType /> </s:element> <s:element name="getVersionTimeResponse"> <s:complexType> <s:sequence> <s:element minOccurs="0" maxOccurs="1" name="getVersionTimeResult" type="s:string" /> </s:sequence> </s:complexType> </s:element> <s:element name="ArrayOfString" nillable="true" type="tns:ArrayOfString" /> <s:element name="string" nillable="true" type="s:string" /> </s:schema> </wsdl:types> <wsdl:message name="getCountryCityByIpSoapIn"> <wsdl:part name="parameters" element="tns:getCountryCityByIp" /> </wsdl:message> <wsdl:message name="getCountryCityByIpSoapOut"> <wsdl:part name="parameters" element="tns:getCountryCityByIpResponse" /> </wsdl:message> <wsdl:message name="getGeoIPContextSoapIn"> <wsdl:part name="parameters" element="tns:getGeoIPContext" /> </wsdl:message> <wsdl:message name="getGeoIPContextSoapOut"> <wsdl:part name="parameters" element="tns:getGeoIPContextResponse" /> </wsdl:message> <wsdl:message name="getVersionTimeSoapIn"> <wsdl:part name="parameters" element="tns:getVersionTime" /> </wsdl:message> <wsdl:message name="getVersionTimeSoapOut"> <wsdl:part name="parameters" element="tns:getVersionTimeResponse" /> </wsdl:message> <wsdl:message name="getCountryCityByIpHttpGetIn"> <wsdl:part name="theIpAddress" type="s:string" /> </wsdl:message> <wsdl:message name="getCountryCityByIpHttpGetOut"> <wsdl:part name="Body" element="tns:ArrayOfString" /> </wsdl:message> <wsdl:message name="getGeoIPContextHttpGetIn" /> <wsdl:message name="getGeoIPContextHttpGetOut"> <wsdl:part name="Body" element="tns:ArrayOfString" /> </wsdl:message> <wsdl:message name="getVersionTimeHttpGetIn" /> <wsdl:message name="getVersionTimeHttpGetOut"> <wsdl:part name="Body" element="tns:string" /> </wsdl:message> <wsdl:message name="getCountryCityByIpHttpPostIn"> <wsdl:part name="theIpAddress" type="s:string" /> </wsdl:message> <wsdl:message name="getCountryCityByIpHttpPostOut"> <wsdl:part name="Body" element="tns:ArrayOfString" /> </wsdl:message> <wsdl:message name="getGeoIPContextHttpPostIn" /> <wsdl:message name="getGeoIPContextHttpPostOut"> <wsdl:part name="Body" element="tns:ArrayOfString" /> </wsdl:message> <wsdl:message name="getVersionTimeHttpPostIn" /> <wsdl:message name="getVersionTimeHttpPostOut"> <wsdl:part name="Body" element="tns:string" /> </wsdl:message> <wsdl:portType name="IpAddressSearchWebServiceSoap"> <wsdl:operation name="getCountryCityByIp"> <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br /><h3>通过输入IP地址查询国家、城市、所有者等信息。没有注明国家的为中国</h3><p>输入参数:IP地址(自动替换 " 。" 为 "."),返回数据: 一个一维字符串数组String(1),String(0) = IP地址;String(1) = 查询结果或提示信息</p><br /></wsdl:documentation> <wsdl:input message="tns:getCountryCityByIpSoapIn" /> <wsdl:output message="tns:getCountryCityByIpSoapOut" /> </wsdl:operation> <wsdl:operation name="getGeoIPContext"> <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br /><h3>获得您的IP地址和地址信息</h3><p>输入参数:无,返回数据: 一个一维字符串数组String(1),String(0) = IP地址;String(1) = 地址信息</p><br /></wsdl:documentation> <wsdl:input message="tns:getGeoIPContextSoapIn" /> <wsdl:output message="tns:getGeoIPContextSoapOut" /> </wsdl:operation> <wsdl:operation name="getVersionTime"> <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br /><h3>获得本IP地址搜索 WEB 服务的数据库版本更新时间</h3><p>输入参数:无,输出参数 String</p><br /></wsdl:documentation> <wsdl:input message="tns:getVersionTimeSoapIn" /> <wsdl:output message="tns:getVersionTimeSoapOut" /> </wsdl:operation> </wsdl:portType> <wsdl:portType name="IpAddressSearchWebServiceHttpGet"> <wsdl:operation name="getCountryCityByIp"> <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br /><h3>通过输入IP地址查询国家、城市、所有者等信息。没有注明国家的为中国</h3><p>输入参数:IP地址(自动替换 " 。" 为 "."),返回数据: 一个一维字符串数组String(1),String(0) = IP地址;String(1) = 查询结果或提示信息</p><br /></wsdl:documentation> <wsdl:input message="tns:getCountryCityByIpHttpGetIn" /> <wsdl:output message="tns:getCountryCityByIpHttpGetOut" /> </wsdl:operation> <wsdl:operation name="getGeoIPContext"> <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br /><h3>获得您的IP地址和地址信息</h3><p>输入参数:无,返回数据: 一个一维字符串数组String(1),String(0) = IP地址;String(1) = 地址信息</p><br /></wsdl:documentation> <wsdl:input message="tns:getGeoIPContextHttpGetIn" /> <wsdl:output message="tns:getGeoIPContextHttpGetOut" /> </wsdl:operation> <wsdl:operation name="getVersionTime"> <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br /><h3>获得本IP地址搜索 WEB 服务的数据库版本更新时间</h3><p>输入参数:无,输出参数 String</p><br /></wsdl:documentation> <wsdl:input message="tns:getVersionTimeHttpGetIn" /> <wsdl:output message="tns:getVersionTimeHttpGetOut" /> </wsdl:operation> </wsdl:portType> <wsdl:portType name="IpAddressSearchWebServiceHttpPost"> <wsdl:operation name="getCountryCityByIp"> <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br /><h3>通过输入IP地址查询国家、城市、所有者等信息。没有注明国家的为中国</h3><p>输入参数:IP地址(自动替换 " 。" 为 "."),返回数据: 一个一维字符串数组String(1),String(0) = IP地址;String(1) = 查询结果或提示信息</p><br /></wsdl:documentation> <wsdl:input message="tns:getCountryCityByIpHttpPostIn" /> <wsdl:output message="tns:getCountryCityByIpHttpPostOut" /> </wsdl:operation> <wsdl:operation name="getGeoIPContext"> <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br /><h3>获得您的IP地址和地址信息</h3><p>输入参数:无,返回数据: 一个一维字符串数组String(1),String(0) = IP地址;String(1) = 地址信息</p><br /></wsdl:documentation> <wsdl:input message="tns:getGeoIPContextHttpPostIn" /> <wsdl:output message="tns:getGeoIPContextHttpPostOut" /> </wsdl:operation> <wsdl:operation name="getVersionTime"> <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><br /><h3>获得本IP地址搜索 WEB 服务的数据库版本更新时间</h3><p>输入参数:无,输出参数 String</p><br /></wsdl:documentation> <wsdl:input message="tns:getVersionTimeHttpPostIn" /> <wsdl:output message="tns:getVersionTimeHttpPostOut" /> </wsdl:operation> </wsdl:portType> <wsdl:binding name="IpAddressSearchWebServiceSoap" type="tns:IpAddressSearchWebServiceSoap"> <soap:binding transport="http://schemas.xmlsoap.org/soap/http" /> <wsdl:operation name="getCountryCityByIp"> <soap:operation soapAction="http://WebXml.com.cn/getCountryCityByIp" style="document" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="getGeoIPContext"> <soap:operation soapAction="http://WebXml.com.cn/getGeoIPContext" style="document" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="getVersionTime"> <soap:operation soapAction="http://WebXml.com.cn/getVersionTime" style="document" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:binding name="IpAddressSearchWebServiceSoap12" type="tns:IpAddressSearchWebServiceSoap"> <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" /> <wsdl:operation name="getCountryCityByIp"> <soap12:operation soapAction="http://WebXml.com.cn/getCountryCityByIp" style="document" /> <wsdl:input> <soap12:body use="literal" /> </wsdl:input> <wsdl:output> <soap12:body use="literal" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="getGeoIPContext"> <soap12:operation soapAction="http://WebXml.com.cn/getGeoIPContext" style="document" /> <wsdl:input> <soap12:body use="literal" /> </wsdl:input> <wsdl:output> <soap12:body use="literal" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="getVersionTime"> <soap12:operation soapAction="http://WebXml.com.cn/getVersionTime" style="document" /> <wsdl:input> <soap12:body use="literal" /> </wsdl:input> <wsdl:output> <soap12:body use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:binding name="IpAddressSearchWebServiceHttpGet" type="tns:IpAddressSearchWebServiceHttpGet"> <http:binding verb="GET" /> <wsdl:operation name="getCountryCityByIp"> <http:operation location="/getCountryCityByIp" /> <wsdl:input> <http:urlEncoded /> </wsdl:input> <wsdl:output> <mime:mimeXml part="Body" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="getGeoIPContext"> <http:operation location="/getGeoIPContext" /> <wsdl:input> <http:urlEncoded /> </wsdl:input> <wsdl:output> <mime:mimeXml part="Body" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="getVersionTime"> <http:operation location="/getVersionTime" /> <wsdl:input> <http:urlEncoded /> </wsdl:input> <wsdl:output> <mime:mimeXml part="Body" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:binding name="IpAddressSearchWebServiceHttpPost" type="tns:IpAddressSearchWebServiceHttpPost"> <http:binding verb="POST" /> <wsdl:operation name="getCountryCityByIp"> <http:operation location="/getCountryCityByIp" /> <wsdl:input> <mime:content type="application/x-www-form-urlencoded" /> </wsdl:input> <wsdl:output> <mime:mimeXml part="Body" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="getGeoIPContext"> <http:operation location="/getGeoIPContext" /> <wsdl:input> <mime:content type="application/x-www-form-urlencoded" /> </wsdl:input> <wsdl:output> <mime:mimeXml part="Body" /> </wsdl:output> </wsdl:operation> <wsdl:operation name="getVersionTime"> <http:operation location="/getVersionTime" /> <wsdl:input> <mime:content type="application/x-www-form-urlencoded" /> </wsdl:input> <wsdl:output> <mime:mimeXml part="Body" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="IpAddressSearchWebService"> <wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"><a href="http://www.webxml.com.cn/" target="_blank">WebXml.com.cn</a> <strong>IP地址搜索 WEB 服务</strong>包含中国和国外已知的IP地址数据,是目前最完整的IP地址数据,记录数量现已超过37万条并还在不断更新和增加中,因IP地址在不断变化,此IP地址数据查询仅供参考。</br>此IP地址搜索Web Services请不要用于任何商业目的,若有需要请<a href="http://www.webxml.com.cn/zh_cn/contact_us.aspx" target="_blank">联系我们</a>,欢迎技术交流。 QQ:8409035<br /><strong>使用本站 WEB 服务请注明或链接本站:http://www.webxml.com.cn/ 感谢大家的支持</strong>!<br /><br />&nbsp;</wsdl:documentation> <wsdl:port name="IpAddressSearchWebServiceSoap" binding="tns:IpAddressSearchWebServiceSoap"> <soap:address location="http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx" /> </wsdl:port> <wsdl:port name="IpAddressSearchWebServiceSoap12" binding="tns:IpAddressSearchWebServiceSoap12"> <soap12:address location="http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx" /> </wsdl:port> <wsdl:port name="IpAddressSearchWebServiceHttpGet" binding="tns:IpAddressSearchWebServiceHttpGet"> <http:address location="http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx" /> </wsdl:port> <wsdl:port name="IpAddressSearchWebServiceHttpPost" binding="tns:IpAddressSearchWebServiceHttpPost"> <http:address location="http://webservice.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx" /> </wsdl:port> </wsdl:service> </wsdl:definitions>
?通过wsdl文档的描述我们可以知道 这个webservice? 对外提供了三个方法:
????getCountryCityByIp ()、getGeoIPContext ()、getVersionTime ()
getCountryCityIp()接受一个String类型的参数,
getGeoIpContext(),这两个方法的返回值是一个对象,我们可以构造一个对象来接收返回的ip地址查询结果
?
将上面的wsdl文件生成java文件:
????wsdl2java -d E:\ http://www.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl
?
按照stubs的开发步骤:
package com.wy.ipclient; import java.util.List; import java.util.Properties; public class IPClient { public static void main(String[] args) { IpAddressSearchWebService iasw = new IpAddressSearchWebService(); // 通过输入IP地址查询国家、城市、所有者等信息 IpAddressSearchWebServiceSoap iasws = iasw .getIpAddressSearchWebServiceSoap12();// getIpAddressSearchWebServiceSoap() ArrayOfString str = iasws.getCountryCityByIp("117.79.73.79"); System.out.println("str.getString()=" + str.getString()); List<?> list = str.getString(); System.out .println("你输入的IP:" + list.get(0) + "\n 你的IP地址:" + list.get(1)); // 获得您的IP地址和地址信息 ArrayOfString aos = iasws.getGeoIPContext(); System.out.println("aos.getString()=" + aos.getString()); List<?> lis = aos.getString(); System.out.println("你的IP地址:" + lis.get(0) + "\n 你的IP来源:" + list.get(1)); } }?
?