the5fire

关注Python、Django、Vim、Linux、Web开发、团队管理和互联网--Life is short, we need Python.


WebService深入学习之三:编写客户端访问你的WebService

作者:the5fire | 标签:     | 发布:2011-01-25 10:46 p.m. | 阅读量: 10702, 10312
接着上篇文章,这里要写一个简单的程序来读取你编写的WebService,使用java语言,当然你也可以使用C#来编写。
首先你需要把引入你的jar包,就是axis的lib目录下的那些东东。
然后编写程序:

package client;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.namespace.QName;

public class MyClient {

public static void main(String[] args) {

try {
String endpoint = "http://localhost:8088/axis/HelloWorld.jws";

Service service = new Service();
Call call = null;

call = (Call) service.createCall();

call.setOperationName(new QName(
"http://localhost:8088/axis/HelloWorld.jws", "sayHello"));
call.setTargetEndpointAddress(new java.net.URL(endpoint));

String ret = (String) call.invoke(new Object[] { "胡阳" });

System.out.println("return value is " + ret);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}

运行一下:

webservice
- from the5fire.com
----EOF-----

微信公众号:Python程序员杂谈


其他分类: