webService(一)客户端快速使用
今天是我第一次写博客,写得不好的地方请多多指教多多包涵!
-
三步完成简单的webservice客户的程序的调用
第一步:使用wsimport命令解析wsdl文件生成本地代码,下面我们拿
http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl网站做试验。
- 1.打开Cmd界面
- 2.进入电脑某个磁盘的某个空文件夹下
-
3.输入wsimport -s .
http://ws.webxml.com.cn/WebServices/MobileCodeWS.asmx?wsdl
-
4.此时,我们打开刚刚所进入的目录文件夹(我这里是E:\test),直接进入到cn\com\webxml,此时可以看到里面有(.class)文件和(.java)文件,我们只需要(.Java)文件,所以删除(.class)文件。
第二步:通过本地代码创建代理对象 -
1.打开eclipse,创建一个Java工程(我这里命名为webservice),再将上一步所获得的(.java)文件拷贝到项目中,如下图所示:
- 2.创建测试类test.java
代码块
代码块语法遵循标准markdown代码,例如:
public class Test {
public static void main(String[] args) {
String phone = "1364013xxxx";
MobileCodeWS mobileCodeWS = new MobileCodeWS();
MobileCodeWSSoap soap = mobileCodeWS.getMobileCodeWSSoap();
String info = soap.getMobileCodeInfo(phone, null);
System.out.println(info);
ArrayOfString aos = soap.getDatabaseInfo();
List<String> list = aos.getString();
for (String string : list) {
System.out.println(string);
}
}
}
-
第三步:通过代理对象实现远程调用
-
执行main函数,得出如下结果:
希望我所写的东西能给您带来帮助!!
如需更多的webservice功能,可登陆www.webxml.com.cn获取。