1、使用JDK自带wsimport工具
wsimport -d ./bin -s ./src -p wei.peng.client http://localhost:8888/WEIPENG/HelloServices?wsdl
在命令行输入上述命令之后,会根据WSDL生成系列相关的辅助类,编译Client端的调用、开发
相当的简单、明了![]()
2、Xfire封装的API Client
很不错的,![]()
package wei.peng.client.test;
import java.net.MalformedURLException;
import java.net.URL;
import org.codehaus.xfire.client.Client;
/**
* 使用Xfire封装的Client API调用Web Services
* @author WPeng
* @time 2011-3-15 下午12:31:25
* @email pengwei841221@126.com
*/
public class TestClient_3_XFire{
public static void main(String[] args) {
try {
Client client = new Client(new URL("http://localhost:10000/XFire1/services/HelloService?wsdl"));
Object[] results = client.invoke("hello", new Object[]{"wei.peng"});
System.out.println(results[0]);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
}
3、可以在浏览器中使用URL直接访问
检查Web Service对不对![]()
在浏览器地址栏输入:
http://localhost/axis/SayHello.jws?method=hello 即可访问方法hello,返回的是整个SOAP数据包。
简单对象访问协议(SOAP,全寫為Simple Object Access Protocol)是一種標準化的通訊規範,主要用于Web服务(web service)中。
<?xml version="1.0" encoding="UTF-8" ?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<helloResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<helloReturn xsi:type="xsd:string">Hello, axis Ver1.4 talking to you.
</helloReturn>
</helloResponse>
</soapenv:Body>
</soapenv:Envelope>
本文介绍了三种调用Web服务的方法:使用JDK自带的wsimport工具生成客户端代码;利用Xfire封装的APIClient进行调用;以及直接通过浏览器访问特定URL来测试WebService的有效性。
403

被折叠的 条评论
为什么被折叠?



