`
v5qqcom
  • 浏览: 1285873 次
文章分类
社区版块
存档分类
最新评论

http://www.javaeye.com/topic/308452

 
阅读更多

http://www.javaeye.com/topic/308452

服务接口,就是用来调用的,所以客户端显得尤为重要,xfire客户端对返回list很挑剔,所以需要使用泛型。

如何建立webservice client

步骤1,建立webservice project

下一步

下一步,默认

选择xfire

finish, 这样,webservice项目就完成了

接下来是如何进行客户端开发.

在项目中右键,new webservice client

接着,选择你服务文件,wsdl

完成。

这样在你的项目中,会根据wsdl服务文件,生成客户端所需要的内容。

自动生成文件,下去就细细体会,给出一个测试代码

Java代码 复制代码
  1. packagecom.seavision.huayi2.service;
  2. importjava.net.MalformedURLException;
  3. importjava.util.Collection;
  4. importjava.util.HashMap;
  5. importjava.util.List;
  6. importjavax.xml.bind.JAXBElement;
  7. importjavax.xml.namespace.QName;
  8. importorg.codehaus.xfire.XFireRuntimeException;
  9. importorg.codehaus.xfire.aegis.AegisBindingProvider;
  10. importorg.codehaus.xfire.annotations.AnnotationServiceFactory;
  11. importorg.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations;
  12. importorg.codehaus.xfire.client.XFireProxyFactory;
  13. importorg.codehaus.xfire.jaxb2.JaxbTypeRegistry;
  14. importorg.codehaus.xfire.service.Endpoint;
  15. importorg.codehaus.xfire.service.Service;
  16. importorg.codehaus.xfire.soap.AbstractSoapBinding;
  17. importorg.codehaus.xfire.transport.TransportManager;
  18. importcom.seavision.huayi2.domain.ArrayOfTBusinsessLog;
  19. importcom.seavision.huayi2.domain.TBusinsessLog;
  20. importcom.seavision.huayi2.domain.TStationMonthReport;
  21. publicclassIWebserviceClient{
  22. privatestaticXFireProxyFactoryproxyFactory=newXFireProxyFactory();
  23. privateHashMapendpoints=newHashMap();
  24. privateServiceservice0;
  25. publicIWebserviceClient(){
  26. create0();
  27. EndpointIWebservicePortTypeLocalEndpointEP=service0.addEndpoint(newQName("http://service.huayi2.seavision.com","IWebservicePortTypeLocalEndpoint"),newQName("http://service.huayi2.seavision.com","IWebservicePortTypeLocalBinding"),"xfire.local://IWebservice");
  28. endpoints.put(newQName("http://service.huayi2.seavision.com","IWebservicePortTypeLocalEndpoint"),IWebservicePortTypeLocalEndpointEP);
  29. EndpointIWebserviceHttpPortEP=service0.addEndpoint(newQName("http://service.huayi2.seavision.com","IWebserviceHttpPort"),newQName("http://service.huayi2.seavision.com","IWebserviceHttpBinding"),"http://localhost:8080/seavision/services/IWebservice");
  30. endpoints.put(newQName("http://service.huayi2.seavision.com","IWebserviceHttpPort"),IWebserviceHttpPortEP);
  31. }
  32. publicObjectgetEndpoint(Endpointendpoint){
  33. try{
  34. returnproxyFactory.create((endpoint).getBinding(),(endpoint).getUrl());
  35. }catch(MalformedURLExceptione){
  36. thrownewXFireRuntimeException("InvalidURL",e);
  37. }
  38. }
  39. publicObjectgetEndpoint(QNamename){
  40. Endpointendpoint=((Endpoint)endpoints.get((name)));
  41. if((endpoint)==null){
  42. thrownewIllegalStateException("Nosuchendpoint!");
  43. }
  44. returngetEndpoint((endpoint));
  45. }
  46. publicCollectiongetEndpoints(){
  47. returnendpoints.values();
  48. }
  49. privatevoidcreate0(){
  50. TransportManagertm=(org.codehaus.xfire.XFireFactory.newInstance().getXFire().getTransportManager());
  51. HashMapprops=newHashMap();
  52. props.put("annotations.allow.interface",true);
  53. AnnotationServiceFactoryasf=newAnnotationServiceFactory(newJsr181WebAnnotations(),tm,newAegisBindingProvider(newJaxbTypeRegistry()));
  54. asf.setBindingCreationEnabled(false);
  55. service0=asf.create((com.seavision.huayi2.service.IWebservicePortType.class),props);
  56. {
  57. AbstractSoapBindingsoapBinding=asf.createSoap11Binding(service0,newQName("http://service.huayi2.seavision.com","IWebservicePortTypeLocalBinding"),"urn:xfire:transport:local");
  58. }
  59. {
  60. AbstractSoapBindingsoapBinding=asf.createSoap11Binding(service0,newQName("http://service.huayi2.seavision.com","IWebserviceHttpBinding"),"http://schemas.xmlsoap.org/soap/http");
  61. }
  62. }
  63. publicIWebservicePortTypegetIWebservicePortTypeLocalEndpoint(){
  64. return((IWebservicePortType)(this).getEndpoint(newQName("http://service.huayi2.seavision.com","IWebservicePortTypeLocalEndpoint")));
  65. }
  66. publicIWebservicePortTypegetIWebservicePortTypeLocalEndpoint(Stringurl){
  67. IWebservicePortTypevar=getIWebservicePortTypeLocalEndpoint();
  68. org.codehaus.xfire.client.Client.getInstance(var).setUrl(url);
  69. returnvar;
  70. }
  71. publicIWebservicePortTypegetIWebserviceHttpPort(){
  72. return((IWebservicePortType)(this).getEndpoint(newQName("http://service.huayi2.seavision.com","IWebserviceHttpPort")));
  73. }
  74. publicIWebservicePortTypegetIWebserviceHttpPort(Stringurl){
  75. IWebservicePortTypevar=getIWebserviceHttpPort();
  76. org.codehaus.xfire.client.Client.getInstance(var).setUrl(url);
  77. returnvar;
  78. }
  79. publicstaticvoidmain(String[]args){
  80. IWebserviceClientclient=newIWebserviceClient();
  81. //createadefaultserviceendpoint
  82. IWebservicePortTypeservice=client.getIWebserviceHttpPort();
  83. /**
  84. *使用ObjectFactory插入
  85. **/
  86. com.seavision.huayi2.domain.ObjectFactorycfactory=newcom.seavision.huayi2.domain.ObjectFactory();
  87. com.seavision.huayi2.domain.TStationMonthReportnewTStationMonthReport=cfactory.createTStationMonthReport();
  88. newTStationMonthReport.setStationMonthReportId(cfactory.createTStationMonthReportStationMonthReportId("123465464864"));
  89. //
  90. /**
  91. *使用JAXBElement插入
  92. **/
  93. //JAXBElement<String>id=newJAXBElement<String>(new
  94. //QName("http://domain.huayi2.seavision.com","stationMonthReportId"),String.class,"gefa");
  95. //newTStationMonthReport.setStationMonthReportId(id);
  96. service.insertYueJiHua(newTStationMonthReport);
  97. /**
  98. *测试返回list结果
  99. **/
  100. ArrayOfTBusinsessLogaot=service.getYeWuList();
  101. Listlist=aot.getTBusinsessLog();
  102. System.out.println(list.size());
  103. for(inti=0;i<list.size();i++){
  104. TBusinsessLogtlog=(TBusinsessLog)list.get(i);
  105. System.out.println(i+"++++++"+tlog.getLogContent().getValue());
  106. }
  107. //TODO:Addcustomclientcodehere
  108. //
  109. //service.yourServiceOperationHere();
  110. System.out.println("testclientcompleted");
  111. System.exit(0);
  112. }
  113. }

注意以下内容,1:返回list内容,先存放入Arrayof**对象当中,再进行list遍历。

2: 对象属性取值,getValue();

3:对象属性封装,通过JAXBElement进行封装后,放入对象。

分享到:
评论

相关推荐

    jquery图片放大镜效果

    本附件下载自 http://www.javaeye.com/topic/626010

    酒店住宿管理系统EXT+Spring+Hibernate+MySql part1

    原址:http://www.javaeye.com/topic/211875 其他:http://www.17ext.com/showtopic-2753.aspx 欢迎加入QQ群:62150370 进行extjs的讨论 如果你没有安装mysql5.0,在安装数据库时,请把root密码设置为neostudio 如果已...

    酒店住宿管理系统EXT+Spring+Hibernate+MySql part2

    原址:http://www.javaeye.com/topic/211875 其他:http://www.17ext.com/showtopic-2753.aspx 欢迎加入QQ群:62150370 进行extjs的讨论 如果你没有安装mysql5.0,在安装数据库时,请把root密码设置为neostudio 如果已...

    毕业设计-酒店住宿管理系统EXT+Spring+Hibernate+MySql(源码共享)

    原址:http://www.javaeye.com/topic/211875 其他:http://www.17ext.com/showtopic-2753.aspx 讨论Q_群:62150370(群1) 76202406(群2) 91986229(群3) 一起讨论 如果你没有安装mysql5.0,在安装数据库时,请把root密码...

    acegi 登录例子

    http://www.javaeye.com/topic/52975 只不过有些不同: 1. 我的spring使用myeclipse向导加入的2.5版本 (附件中不包含) 2. 我加入的是(源代码中已存在): acegi-security-1.0.7.jar 加入了数据库驱动(mysql5...

    Java版山寨星际----下载不扣分,回帖加1分,欢迎下载,童叟无欺

    ---javaeye相关地址:http://www.javaeye.com/topic/379655 ---Java版山寨星际 做了一大堆J2EE WEB应用之后,闲来无事决定研究一下桌面应用程序开发。 想了一下干脆做个Java版的星际,研究的对象就是星际的JS山寨版...

    AbatorForEclipse1.1.0.zip

    详情请参考 http://www.javaeye.com/topic/170187

    【您的设计模式】趣味介绍23种设计模式

    http://www.javaeye.com/topic/372233

    Hibernate 缓存

    Hibernate 缓存详细介绍http://www.javaeye.com/wiki/topic/571245

    SQL PLUS命令 sql编程手册.doc

    网上看到一个有关SQL*PLUS的文章,比较不错。在这里与大家分享。 原作者网址:http://www.javaeye.com/topic/423094

    osworkflow eclipse+mysql 请假审批流程 完整示例

    从javaeye上下载别人的例子,感觉不错 另外在这里有详细介绍 http://www.javaeye.com/topic/100499?page=1

    mootools1.11中文文档

    刚翻译完成的 Mootools v1.11 中文文档(完整版,文档格式CHM) 转自 http://www.javaeye.com/topic/126290

    xfire开发在weblogic8上需要的jar包

    xfire+weblogic8+jdk1.4所需要的jar包,包括客户端开发所需要的jar包,使用说明请见http://www.javaeye.com/topic/361269

    MyEclipse6.5配置反编译插件

    转自 http://www.javaeye.com/topic/890512 MyEclipse6.5的反编译插件的安装 我的MyEclipse6.5的安 装目录是D:\MyEclipse 6.5,以下仅供参考 第一步: 下载jad.exe(Jad v1.5.8g版本)和net.sf.jadclipse_3.3.0.jar;...

    jquery flexigrid插件

    Flexigrid-Web2.0 jQuery表格插件 Flexigrid 是一个轻量级的Web2.0 jQuery插件。它包含很多非常Cool的特性,如主题定制、分页、工具栏、搜索、排序、ajax读取数据源、调整列宽...http://www.javaeye.com/topic/414611

    ruby勇士,边玩边学习

    ruby勇士,初学者边游戏边学习ruby的好玩的东西。具体玩法在 http://www.javaeye.com/topic/383938,或者Google一下“ruby勇士”。因为下载游戏的网站有时访问不了,上传一下提供下载。

    struts2.1宝典

    http://www.javaeye.com/topic/128973 1 struts2表单标签 1 1、struts资源文件中文解决方法 1 2、开发struts2流程 1 3、创建拦截器: 2 4.标签中引用资源文件内容 3 5.创建资源文件 3 6.Action中访问servlet API 3...

    Tomcat内存溢出的三种情况及解决办法分析

    http://www.javaeye.com/topic/80620?page=1 的帖子有讨论的这个问题。可能是由于这些框架会动态class,而且jvm的gc是不会清理PemGen space的,导致内存溢出。 这一个一般是加大-XX:PermSize -XX:MaxPermSize 来...

    Chart 极品web报表控件收集(Flot,AmCharts, Emprise JavaScript Charts...)

    Web Chart Flot - Flot 为 jQuery 提供的javascript代码库. 容易使用,有特色的图表,提供交互功能(能够放大缩小数据区域等)。 ... • AmCharts - AmCharts ... GoogleChart - http://www.javaeye.com/topic/219853

    一个java正则表达式工具类源代码.zip(内含Regexp.java文件)

    前言:本资源来自于javaeye,原资源链接地址:http://www.javaeye.com/topic/67398 原文如下: 以前写了一个java的正规表达式的java工具类,分享一下,有用到的欢迎下载使用。 如果你有常用的定义好的,且测试通过的...

Global site tag (gtag.js) - Google Analytics