`

在MyEclipse中调用WebService

阅读更多
1.如果web service发布成功了,就要看如何使用这web service

根据WSDL生成客户端代码,我们采用eclipse plugin 这样更简单,也可采用ant

具体xfire插件安装: Help ->Software Updates->Find and Install->Search for new features to install->Create New Remote Site,并输入"XFire" 名字和http://dist.codehaus.org/xfire/update/ eclipse 更新站点。

2.File->new ->Other->XFire->Code generation from WSDL document

输入WSDL URL或PATH,以及要生成的客户端代码目录。


3.测试:

import cares.cn.helloservice.HelloServiceClient;

import cares.cn.helloservice.HelloServicePortType;


public class Test {

    public static void main(String[] args) {

       HelloServiceClient client = new HelloServiceClient();

       HelloServicePortType helloService = client.getHelloServiceHttpPort();

//     调用服务

       String result = helloService.hello("Tome");

       System.out.println("结果:" + result);

    }


}

注意:当运行时可能失败,是因为提示缺少jar包,因此,要将commons-codec-1.3.jar和commons-httpclient-3.0.jar只放到lib中并在工程中引用

如果输出:HI,Tome 说明客户端调用web service 成功。整个过程就完成了。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics