您的位置:首页 > 编程语言 > Java开发

由wsdl快速生成客户端java代码

2014-03-10 15:36 495 查看
1.在eclipse3.x中新建一个项目,如wsdemoClient

2.启动提供方法的webservices服务,如项目?,并且获取相关方法的wsdl文件.

3.将wsdl文件复制到wsdemoClient的项目中.

4.新建一个webservice Client,方法如下:file->new->other->webServices->Web Service Client

5.在弹出来的窗口中选中wsdemoClient项目中的wsdl文件.依次操作完成.

6.成功后,wsdemoClient就生成了java代码.

7.编写客户端测试程序:如下:
public class Test {public static void main(String[] str) {RemoteMethodSoapBindingStub binding;try {binding = (RemoteMethodSoapBindingStub) new RemoteMethodServiceLocator().getRemoteMethod();
// 取接口binding.setTimeout(60000); // 设置超时时间String msg = binding.getMessage("tangxingyou"); // 调用hello方法System.out.println(">>>>>>>>>>>>>>>>服务器返回消息:");System.out.println(msg);System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");} catch (javax.xml.rpc.ServiceException
ex) {if (ex.getLinkedCause() != null)ex.getLinkedCause().printStackTrace();System.out.println("JAX-RPC调用出错:");ex.printStackTrace();} catch (RemoteException ex) {System.out.println("Web Service调用出错:");ex.printStackTrace();}}}

8.运行Test程序.(前提webservices服务端已经启动)

9.这样可以把这些源代码复制到需要调用webservices的项目中去,调用的方法就如Test.java.当然相关的包也要导进去!!?

在本地一直生成出错,又找厂家,又翻资料,结果原因竟然是网络问题
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: