首先,要获得搭建好的WebService服务的WSDL,如要实现国内手机号码归属地查询WEB服务,其WSDL为:http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?WSDL
拿到WSDL后在浏览器打开看服务是否正常:

打开cmd,运行命令:
wsimport -p com -s . http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?WSDL

找到解析位置,复制相关Java文件到客户端:


写测试类,直接调用相关接口:
import mobileWebService.MobileCodeWS;
import mobileWebService.MobileCodeWSSoap;
public class MobileWebServiceTest {
public static void main(String[] args) {
//获取webservice服务器对象(这里的类名,其实是从wsdl文件中的servicename标签中进行获取的)
MobileCodeWS mobileCodeWS = new MobileCodeWS();
MobileCodeWSSoap m = mobileCodeWS.getMobileCodeWSSoap();
String str = m.getMobileCodeInfo("手机号码", "");
System.out.println(str);
}
}
运行结果:

WebService服务遇到问题及解决办法:https://www.cnblogs.com/Big-Boss/p/11912679.html
原文:https://www.cnblogs.com/Big-Boss/p/11956335.html