cas+ldap异常分析 | xfire+webservice(服务器配置篇)
2008-12-31

xfire+webservice(客户端调用篇)

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

如何建立webservice client

步骤1,建立webservice  project

下一步

下一步,默认

选择xfire包

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

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

在项目中右键,new webservice client

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

完成。

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

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

Java代码
  1. package com.seavision.huayi2.service;
  2. import java.net.MalformedURLException;
  3. import java.util.Collection;
  4. import java.util.HashMap;
  5. import java.util.List;
  6. import javax.xml.bind.JAXBElement;
  7. import javax.xml.namespace.QName;
  8. import org.codehaus.xfire.XFireRuntimeException;
  9. import org.codehaus.xfire.aegis.AegisBindingProvider;
  10. import org.codehaus.xfire.annotations.AnnotationServiceFactory;
  11. import org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations;
  12. import org.codehaus.xfire.client.XFireProxyFactory;
  13. import org.codehaus.xfire.jaxb2.JaxbTypeRegistry;
  14. import org.codehaus.xfire.service.Endpoint;
  15. import org.codehaus.xfire.service.Service;
  16. import org.codehaus.xfire.soap.AbstractSoapBinding;
  17. import org.codehaus.xfire.transport.TransportManager;
  18. import com.seavision.huayi2.domain.ArrayOfTBusinsessLog;
  19. import com.seavision.huayi2.domain.TBusinsessLog;
  20. import com.seavision.huayi2.domain.TStationMonthReport;
  21. public class IWebserviceClient {
  22. private static XFireProxyFactory proxyFactory = new XFireProxyFactory();
  23. private HashMap endpoints = new HashMap();
  24. private Service service0;
  25. public IWebserviceClient() {
  26. create0();
  27. Endpoint IWebservicePortTypeLocalEndpointEP = service0 .addEndpoint(new QName("http://service.huayi2.seavision.com", "IWebservicePortTypeLocalEndpoint"), new QName("http://service.huayi2.seavision.com", "IWebservicePortTypeLocalBinding"), "xfire.local://IWebservice");
  28. endpoints.put(new QName("http://service.huayi2.seavision.com", "IWebservicePortTypeLocalEndpoint"), IWebservicePortTypeLocalEndpointEP);
  29. Endpoint IWebserviceHttpPortEP = service0 .addEndpoint(new QName("http://service.huayi2.seavision.com", "IWebserviceHttpPort"), new QName("http://service.huayi2.seavision.com", "IWebserviceHttpBinding"), "http://localhost:8080/seavision/services/IWebservice");
  30. endpoints.put(new QName("http://service.huayi2.seavision.com", "IWebserviceHttpPort"), IWebserviceHttpPortEP);
  31. }
  32. public Object getEndpoint(Endpoint endpoint) {
  33. try {
  34. return proxyFactory.create((endpoint).getBinding(), (endpoint).getUrl());
  35. catch (MalformedURLException e) {
  36. throw new XFireRuntimeException("Invalid URL", e);
  37. }
  38. }
  39. public Object getEndpoint(QName name) {
  40. Endpoint endpoint = ((Endpoint) endpoints.get((name)));
  41. if ((endpoint) == null) {
  42. throw new IllegalStateException("No such endpoint!");
  43. }
  44. return getEndpoint((endpoint));
  45. }
  46. public Collection getEndpoints() {
  47. return endpoints.values();
  48. }
  49. private void create0() {
  50. TransportManager tm = (org.codehaus.xfire.XFireFactory.newInstance().getXFire().getTransportManager());
  51. HashMap props = new HashMap();
  52. props.put("annotations.allow.interface", true);
  53. AnnotationServiceFactory asf = new AnnotationServiceFactory(new Jsr181WebAnnotations(), tm, new AegisBindingProvider(new JaxbTypeRegistry()));
  54. asf.setBindingCreationEnabled(false);
  55. service0 = asf.create((com.seavision.huayi2.service.IWebservicePortType.class), props);
  56. {
  57. AbstractSoapBinding soapBinding = asf.createSoap11Binding(service0, new QName("http://service.huayi2.seavision.com", "IWebservicePortTypeLocalBinding"), "urn:xfire:transport:local");
  58. }
  59. {
  60. AbstractSoapBinding soapBinding = asf.createSoap11Binding(service0, new QName("http://service.huayi2.seavision.com", "IWebserviceHttpBinding"), "http://schemas.xmlsoap.org/soap/http");
  61. }
  62. }
  63. public IWebservicePortType getIWebservicePortTypeLocalEndpoint() {
  64. return ((IWebservicePortType)(this).getEndpoint(new QName("http://service.huayi2.seavision.com", "IWebservicePortTypeLocalEndpoint")));
  65. }
  66. public IWebservicePortType getIWebservicePortTypeLocalEndpoint(String url) {
  67. IWebservicePortType var = getIWebservicePortTypeLocalEndpoint();
  68. org.codehaus.xfire.client.Client.getInstance(var).setUrl(url);
  69. return var;
  70. }
  71. public IWebservicePortType getIWebserviceHttpPort() {
  72. return ((IWebservicePortType)(this).getEndpoint(new QName("http://service.huayi2.seavision.com", "IWebserviceHttpPort")));
  73. }
  74. public IWebservicePortType getIWebserviceHttpPort(String url) {
  75. IWebservicePortType var = getIWebserviceHttpPort();
  76. org.codehaus.xfire.client.Client.getInstance(var).setUrl(url);
  77. return var;
  78. }
  79. public static void main(String[] args) {
  80. IWebserviceClient client = new IWebserviceClient();
  81. //create a default service endpoint
  82. IWebservicePortType service = client.getIWebserviceHttpPort();
  83. /**
  84. * 使用ObjectFactory插入
  85. * */
  86. com.seavision.huayi2.domain.ObjectFactory cfactory=new com.seavision.huayi2.domain.ObjectFactory();
  87. com.seavision.huayi2.domain.TStationMonthReport  newTStationMonthReport = cfactory.createTStationMonthReport();
  88. newTStationMonthReport.setStationMonthReportId(cfactory.createTStationMonthReportStationMonthReportId("123465464864"));
  89. //
  90. /**
  91. * 使用JAXBElement插入
  92. * */
  93. //            JAXBElement<String> id = new JAXBElement<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. ArrayOfTBusinsessLog aot = service.getYeWuList();
  101. List list = aot.getTBusinsessLog();
  102. System.out.println(list.size());
  103. for(int i=0;i<list.size();i++){
  104. TBusinsessLog tlog = (TBusinsessLog) list.get(i);
  105. System.out.println(i+"++++++"+tlog.getLogContent().getValue());
  106. }
  107. //TODO: Add custom client code here
  108. //
  109. //service.yourServiceOperationHere();
  110. System.out.println("test client completed");
  111. System.exit(0);
  112. }
  113. }
package com.seavision.huayi2.service;import java.net.MalformedURLException;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import org.codehaus.xfire.XFireRuntimeException;
import org.codehaus.xfire.aegis.AegisBindingProvider;
import org.codehaus.xfire.annotations.AnnotationServiceFactory;
import org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.jaxb2.JaxbTypeRegistry;
import org.codehaus.xfire.service.Endpoint;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.soap.AbstractSoapBinding;
import org.codehaus.xfire.transport.TransportManager;import com.seavision.huayi2.domain.ArrayOfTBusinsessLog;
import com.seavision.huayi2.domain.TBusinsessLog;
import com.seavision.huayi2.domain.TStationMonthReport;public class IWebserviceClient {private static XFireProxyFactory proxyFactory = new XFireProxyFactory();private HashMap endpoints = new HashMap();private Service service0;public IWebserviceClient() {create0();Endpoint IWebservicePortTypeLocalEndpointEP = service0 .addEndpoint(new QName("http://service.huayi2.seavision.com", "IWebservicePortTypeLocalEndpoint"), new QName("http://service.huayi2.seavision.com", "IWebservicePortTypeLocalBinding"), "xfire.local://IWebservice");endpoints.put(new QName("http://service.huayi2.seavision.com", "IWebservicePortTypeLocalEndpoint"), IWebservicePortTypeLocalEndpointEP);Endpoint IWebserviceHttpPortEP = service0 .addEndpoint(new QName("http://service.huayi2.seavision.com", "IWebserviceHttpPort"), new QName("http://service.huayi2.seavision.com", "IWebserviceHttpBinding"), "http://localhost:8080/seavision/services/IWebservice");endpoints.put(new QName("http://service.huayi2.seavision.com", "IWebserviceHttpPort"), IWebserviceHttpPortEP);}public Object getEndpoint(Endpoint endpoint) {try {return proxyFactory.create((endpoint).getBinding(), (endpoint).getUrl());} catch (MalformedURLException e) {throw new XFireRuntimeException("Invalid URL", e);}}public Object getEndpoint(QName name) {Endpoint endpoint = ((Endpoint) endpoints.get((name)));if ((endpoint) == null) {throw new IllegalStateException("No such endpoint!");}return getEndpoint((endpoint));}public Collection getEndpoints() {return endpoints.values();}private void create0() {TransportManager tm = (org.codehaus.xfire.XFireFactory.newInstance().getXFire().getTransportManager());HashMap props = new HashMap();props.put("annotations.allow.interface", true);AnnotationServiceFactory asf = new AnnotationServiceFactory(new Jsr181WebAnnotations(), tm, new AegisBindingProvider(new JaxbTypeRegistry()));asf.setBindingCreationEnabled(false);service0 = asf.create((com.seavision.huayi2.service.IWebservicePortType.class), props);{AbstractSoapBinding soapBinding = asf.createSoap11Binding(service0, new QName("http://service.huayi2.seavision.com", "IWebservicePortTypeLocalBinding"), "urn:xfire:transport:local");}{AbstractSoapBinding soapBinding = asf.createSoap11Binding(service0, new QName("http://service.huayi2.seavision.com", "IWebserviceHttpBinding"), "http://schemas.xmlsoap.org/soap/http");}}public IWebservicePortType getIWebservicePortTypeLocalEndpoint() {return ((IWebservicePortType)(this).getEndpoint(new QName("http://service.huayi2.seavision.com", "IWebservicePortTypeLocalEndpoint")));}public IWebservicePortType getIWebservicePortTypeLocalEndpoint(String url) {IWebservicePortType var = getIWebservicePortTypeLocalEndpoint();org.codehaus.xfire.client.Client.getInstance(var).setUrl(url);return var;}public IWebservicePortType getIWebserviceHttpPort() {return ((IWebservicePortType)(this).getEndpoint(new QName("http://service.huayi2.seavision.com", "IWebserviceHttpPort")));}public IWebservicePortType getIWebserviceHttpPort(String url) {IWebservicePortType var = getIWebserviceHttpPort();org.codehaus.xfire.client.Client.getInstance(var).setUrl(url);return var;}public static void main(String[] args) {IWebserviceClient client = new IWebserviceClient();//create a default service endpointIWebservicePortType service = client.getIWebserviceHttpPort();/*** 使用ObjectFactory插入* */    com.seavision.huayi2.domain.ObjectFactory cfactory=new com.seavision.huayi2.domain.ObjectFactory();com.seavision.huayi2.domain.TStationMonthReport  newTStationMonthReport = cfactory.createTStationMonthReport();newTStationMonthReport.setStationMonthReportId(cfactory.createTStationMonthReportStationMonthReportId("123465464864"));
//            /*** 使用JAXBElement插入* *///            JAXBElement<String> id = new JAXBElement<String>(new
//                    QName("http://domain.huayi2.seavision.com", "stationMonthReportId"),String.class,"gefa");
//            newTStationMonthReport.setStationMonthReportId(id);service.insertYueJiHua(newTStationMonthReport);/*** 测试返回list结果* */ArrayOfTBusinsessLog aot = service.getYeWuList();List list = aot.getTBusinsessLog();System.out.println(list.size());for(int i=0;i<list.size();i++){TBusinsessLog tlog = (TBusinsessLog) list.get(i);System.out.println(i+"++++++"+tlog.getLogContent().getValue());}//TODO: Add custom client code here////service.yourServiceOperationHere();System.out.println("test client completed");System.exit(0);}}

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

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

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

  • 大小: 41.4 KB
  • 大小: 46.1 KB
  • 大小: 44.1 KB
  • 大小: 47 KB
  • 大小: 36.7 KB
  • 大小: 48.6 KB
  • 查看图片附件
  • 16:25
  • 浏览 (168)
  • 论坛浏览 (373)
  • 评论 (1)
  • 收藏
  • 相关推荐

转载于:https://www.cnblogs.com/cy163/archive/2009/03/21/1418153.html

xfire客户端对返回list很挑剔,所以需要使用泛型。相关推荐

  1. xfire客户端获取xcf服务端接口解析问题

    1.java.lang.ClassCastException: org.apache.xerces.dom.DocumentImpl cannot be cast to java.lang.Strin ...

  2. Tencent APIJSON 零代码、全功能、强安全 ORM 库 后端接口和文档零代码,前端(客户端) 定制返回 JSON 的数据和结构

    项目介绍 零代码.全功能.强安全 ORM 库 后端接口和文档零代码,前端(客户端) 定制返回 JSON 的数据和结构. A JSON Transmission Protocol and an ORM ...

  3. springboot上传文件过大,全局异常捕获,客户端没有返回值

    springboot上传文件过大,全局异常捕获,客户端没有返回值 参考文章: (1)springboot上传文件过大,全局异常捕获,客户端没有返回值 (2)https://www.cnblogs.co ...

  4. 服务器共享文件搜索慢的原因,客户端访问服务器共享文件反应很慢.doc

    文档介绍: windows2003域中,客户端访问服务器共享文件,反应很慢 windows2003组建的域,全部使用xp作为客户端,其他的电脑访问服务器上的共享文件都很快,只有一台反应明显延时.请问是 ...

  5. xfire客户端调用服务端报错 XFireRuntimeException: Could not invoke service.. Server returned error code = 4ji

     xfire客户端调用xfire服务端报错 org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Server ...

  6. python自动化客户端_如何使用Python自动化登录客户端,pywinauto确实很强大

    工作中会遇见很多重复性的工作,如何让自己懒一点,可以不用每天去做这些,而是去自动化完成一些市场呢? 首先,我们需要登录客户端,如plsql.qq.邮箱.钉钉等等,网上百度过很多方法,发现都是已txt文 ...

  7. java xfire 客户端代码_java调用xfire webService服务客户端代码

    java技术调用xfire webService服务客户端代码 import类: import java.net.MalformedURLException; import java.net.URL; ...

  8. java ftp限速_为什么Java FTP客户端的传输速率存在很大差异

    也许有人可以回答我这个问题.在我最近的工作中,我注意到我的应用程序(通过FTP下载更新)在与 Linux一起使用时非常慢.我在Mac上开发这些东西,所以我之前没有注意到这个问题,因为Mac OS下的下 ...

  9. Maximo中调用XFire客户端的实现—Weblogic中间件

    2019独角兽企业重金招聘Python工程师标准>>> 1.在Maximo工程中创建com.test.webservice包. 2.保存将http://test:8080/test/ ...

最新文章

  1. 宽度优先遍历(BFS)
  2. 类 求数组最大最小平均
  3. sklearn MLP(多层感知机、Multi-layer Perceptron)模型使用RandomSearchCV获取最优参数及可视化
  4. nginx FastCGI错误Primary script unknown解决办法
  5. BZOJ 2287 【POJ Challenge】消失之物
  6. Android基于回调的事件处理
  7. 逆向工程核心原理学习笔记(十四):栈帧1
  8. Tech·Ed 2009
  9. 13.表格标签及其应用实例
  10. oracle em配置报错,oracle em 启动报错OC4J Configuration issue
  11. Python调用Java代码部署及初步使用
  12. Android ListView下拉刷新时卡的问题解决小技巧
  13. VMware HA实战攻略之一软硬件环境准备
  14. JavaScript HTML DOM 1
  15. 程序员的每个阶段,都应该需要思考自己要什么?
  16. Java ConcurrentHashMap
  17. linux 使用 ioctl 参数
  18. 安泰测试新手教程-泰克数字示波器使用方法
  19. html5 在线抽奖,HTML5大转盘抽奖特效代码
  20. Win7系统怎么开启远程桌面?Win7远程桌面怎么用

热门文章

  1. 做最好的自己——读书笔记
  2. linux 定时备份mysql数据库
  3. MVC + LigerUI 做后台管理还真是清爽
  4. C# 淘宝商品微信返利助手开发-(三)返利助手开发(1)API介绍
  5. excel按季度分类汇总_Excel数据分析实战(1)--电商销售记录分析
  6. 第8章-常用优先级和css3
  7. 教你配置支付宝应用网关和授权回调地址
  8. python3 venv 虚拟环境使用
  9. 2020计算机领域前沿热门技术,CFP: ICPCSEE 2020 (SCI or EI Indexd) 第6届国际计算机前沿大会...
  10. java spring注入 静态方法_java相关:spring为类的静态属性实现注入实例方法