由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.当然相关的包也要导进去!!?
在本地一直生成出错,又找厂家,又翻资料,结果原因竟然是网络问题
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.当然相关的包也要导进去!!?
在本地一直生成出错,又找厂家,又翻资料,结果原因竟然是网络问题
相关文章推荐
- [2014-03-07]JAVA笔记_继承、方法重写
- spring - quartz - experssion 表达式
- java POI创建Excel示例(xslx和xsl区别 )
- 认识JAVA
- Eclipse 浏览文件插件 OpenExplorer
- Java界面 SWT基本组件——列表框(List)
- Java的内存泄漏
- jdk配置环境变量
- JAVA注释规范
- javaWeb 之 XML基础(一)
- 遭遇Spring MVC+MySQL保存中文变成乱码
- spring mvc注解例子
- spring 配置文件
- JAVA事务的概念
- struts2.2.3需要11个基本包
- JAVA事务的概念
- 同包不同文件,继承接口,编译出错:java错误找不到符号
- JAVA 的对象初始化过程
- 取消Eclipse中Java的一些预警。
- JAVA中的static方法