首页 技术 正文
技术 2022年11月6日
0 收藏 878 点赞 344 浏览 1188 个字

  首先,要获得搭建好的WebService服务的WSDL,如要实现国内手机号码归属地查询WEB服务,其WSDL为:http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?WSDL

  拿到WSDL后在浏览器打开看服务是否正常:

客户端实现WebService服务接口

  

第一种:

  打开cmd,运行命令:

wsimport -p com -s . http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?WSDL

客户端实现WebService服务接口

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

客户端实现WebService服务接口

客户端实现WebService服务接口

  写测试类,直接调用相关接口:

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服务接口

第二种: 

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;/**
* 基于cxf客户端调用WebService测试
*/
public class WebServiceClient { public static void main(String[] args) throws Exception {
JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
Client client = dcf.createClient("http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?WSDL");
Object[] result = client.invoke("getMobileCodeInfo", "手机号码", "");
System.out.println(result[0]);
}
}

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

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,085
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,560
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,409
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,182
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,819
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,902