当前位置: 首页 > 工具软件 > Axis Mundi > 使用案例 >

Axis入门(3)

陈正业
2023-12-01

WEB services客户端例子

说明:本文材料取自Axis user's guide
在Apache的公共Axis服务器上有一个echoString的服务,你向该服务发一个串,该服务能够返回同一个串给你.下面我们写一个WEB services客户端例子来调用该服务:
1?? import org.apache.axis.client.Call;
2?? import org.apache.axis.client.Service;
3?? import javax.xml.namespace.QName;
4??
5?? public class TestClient {
6????? public static void main(String [] args) {
7????????? try {
8????????????? String endpoint =
9?????????????????????? "http://nagoya.apache.org:5049/axis/services/echo";
10?
?????????????? //创建两个JAX-RPC对象
11???????????? Service? service = new Service();
12???????????? Call???? call??? = (Call) service.createCall();
13?
?????????????? //SOAP消息的目的地
14???????????? call.setTargetEndpointAddress( new java.net.URL(endpoint) );
?????????????? //要调用的操作名称
15???????????? call.setOperationName(new QName("http://soapinterop.org/", "echoString"));
16?
?????????????? //用数组形式传入参数
17???????????? String ret = (String) call.invoke( new Object[] { "Hello!" } );
18?
19???????????? System.out.println("Sent 'Hello!', got '" + ret + "'");
20???????? } catch (Exception e) {
21???????????? System.err.println(e.toString());
22???????? }
23???? }
24? }
上面的文件在axis的D:/axis/axis-1_1/samples/userguide/example1目录下.

加入需要的包,连接上网络,运行程序,你将得到下面的结果:
Sent 'Hello!', got 'Hello!'

用tcpmon或SOAP monitor工具查看传递的SOAP消息,如下:

http://www.w3.org/2001/XMLSchema"
?????????????????? xmlns:SOAP-ENV=" http://schemas.xmlsoap.org/soap/envelope/"
?????????????????? xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance">
?
??? http://soapinterop.org/">
????? Hello!
???
?

这个就是一个符合SOAP规范的文件了.

 类似资料: