webService客户端搭建(三)
原文:http://www.cnblogs.com/xdp-gacl/p/4259481.html
1.生成本地wsdl文件
在项目src目录下打开cmd,输入
wsimport -keep http://10.4.17.129:14321/wbeService_01/WebService?wsdl
命令目的为在本地创建服务器提供的代码,以便于引用
本地生成文件:
调用webService
package me.gacl.ws.client; import me.gacl.ws.WebServiceImpl; import me.gacl.ws.WebServiceImplService; public class WSClient { public static void main(String[] args) { // 通过实例引用获得实例工厂 WebServiceImplService factory = new WebServiceImplService(); // 通过工厂得到实现类 WebServiceImpl wsImpl = factory.getWebServiceImplPort(); // 通过实现类调用方法 String save = wsImpl.save("11", "22"); System.out.println(save); } }
二.手机号码归属地查询webService引用
网址:
http://www.webxml.com.cn/zh_cn/index.aspx:wsdl
cmd输入:
wsimport -keep http://www.webxml.com.cn/zh_cn/index.aspx:wsdl
导入后
调用:
package me.gacl.ws.client; import me.gacl.phonenum.MobileCodeWS; import me.gacl.phonenum.MobileCodeWSSoap; public class PhoneNumCilent { public static void main(String[] args) { MobileCodeWS ws = new MobileCodeWS(); MobileCodeWSSoap port = ws.getPort(MobileCodeWSSoap.class); String mobileCodeInfo = port.getMobileCodeInfo("141123", null); System.out.println(mobileCodeInfo); } }