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

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

xfire+webservice(客户端调用篇)

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

     如何建立webservice client

     步骤1,建立webservice  project

    3dd957c0-06cc-377f-b8cd-c7119cce07d5.jpg

    下一步

    a7a9a430-8186-3277-ac39-70905566acf4.jpg

    下一步,默认

    be82bc5c-615a-39c0-b3ab-fdf24fa90820.jpg

    选择xfire

    0ea2eaf7-5765-3e4d-843a-b1913c8a2b2d.jpg

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

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

    在项目中右键,new webservice client

    ce11f88b-9f25-3d3a-abb3-d0875db1fef0.jpg

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

    6179b30d-5f11-3506-a27f-0d938e84b908.jpg

   完成。

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

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

  

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

  • 3dd957c0-06cc-377f-b8cd-c7119cce07d5-thumb
  • 大小: 41.4 KB
  • A7a9a430-8186-3277-ac39-70905566acf4-thumb
  • 大小: 46.1 KB
  • Be82bc5c-615a-39c0-b3ab-fdf24fa90820-thumb
  • 大小: 44.1 KB
  • 0ea2eaf7-5765-3e4d-843a-b1913c8a2b2d-thumb
  • 大小: 47 KB
  • Ce11f88b-9f25-3d3a-abb3-d0875db1fef0-thumb
  • 大小: 36.7 KB
  • 6179b30d-5f11-3506-a27f-0d938e84b908-thumb
  • 大小: 48.6 KB
  • 查看图片附件
  • 16:25
  • 浏览 (168)
  • 论坛浏览 (373)
  • 评论 (1)
  • 收藏
  • 相关推荐

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/435911.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C语言关键字----Const

C中CONST的使用&#xff1a;   虽然这听起来很简单&#xff0c;但实际上&#xff0c;const的使用也是c语言中一个比较微妙的地方&#xff0c;微妙在何处呢&#xff1f;请看下面几个问题。   问题&#xff1a;const变量 & 常量   为什么下面的例子在使用一个const变量…

【转】DICOM的常用Tag分类和说明!!!!

转自&#xff1a;https://www.cnblogs.com/stephen2014/p/4579443.html 有删改 1. 前言&#xff1a; 基于DICOM3.0标准的医学图像中&#xff0c;每一张图像中都携带着许多的信息&#xff0c;这些信息主要可以分为Patient, Study, Series和Image四类。每一个DICOM Tag都是…

计算机卡在无法显示网页,我的电脑上网上银行一直“无法显示网页”

首先&#xff1a;打开一个网页&#xff0c;点击“工具”&#xff0d;&#xff0d;internet选项&#xff0d;&#xff0d;高级&#xff0d;&#xff0d;还原默认设置&#xff0d;&#xff0d;应用&#xff0d;&#xff0d;确定 其次&#xff1a;使用这个修复工具试一试&#xff…

在虚拟机上运行vxWorks

Vxworks是一个嵌入式系统&#xff0c;主要运行在arm、ppc、mips等嵌入式处理器上&#xff0c;它同样可以运行在X86处理器上。风河公司开发的tornado开发环境就 包括了pentium版本&#xff0c;并且发布了相应的bsp。因此我们可在vmware虚拟机上运行vxworks&#xff0c;利用虚拟机…

【转】成熟的医学影像“调窗”(window-leveling)算法详解

转自&#xff1a;http://blog.sina.com.cn/s/blog_4bce5f4b0100o9iy.html 图像显示和打印面临的一个问题是&#xff1a;图像的亮度和对比度能否充分突出关键部分。这里所指的“关键部分”在 CT 里的例子有软组织、骨头、脑组织、肺、腹部等等。 技术问题&#xff1a; 显示…

南京大学计算机系副教授名单,2018年度国际“人工智能10大新星”名单公布:南京大学俞扬副教授国内高校入选者...

中公考研小编为各位考研小伙伴们整理了关于2018年度国际“人工智能10大新星”名单公布&#xff1a;南京大学俞扬副教授国内高校唯一入选者的相关资讯文章&#xff0c;一起了解一下吧~日前&#xff0c;国际人工智能领域著名杂志 IEEE Intelligent Systems 发布了2018年度“人工智…

使用SDL打造游戏世界之入门篇 - 7

打开和显示图片在这个例子里我们将学习如何使用SDL程序中打开和显示图片。示例程序将绘制一个漂亮的背景&#xff0c;上面显示一个正方形图案&#xff0c;并可以使用键盘的方向键移动它。如果比较熟悉“推箱子”这个游戏&#xff0c;可以看出这个程序实际就是推箱子游戏的基础。…

WDB

1. 符号表同步貌似只能是target shell下载后&#xff0c;能够在host shell下更新&#xff0c;当host shell下载的话&#xff0c;target shell是无法更新的。 2. host shell下执行某一个函数的时候&#xff0c;WDB会自动生成一个新的任务来运行&#xff0c;这个任务的IO将被重定…

【转】GPS从入门到放弃(一) --- GPS基础原理

转自&#xff1a;https://blog.csdn.net/tyst08/article/details/100529424 GPS从入门到放弃&#xff08;一&#xff09; — GPS基础原理 GPS&#xff0c;全称Global Positioning System&#xff0c;已经广泛应用于我们的日常生活中了&#xff0c;现在的智能手机 里都会自带G…

计算机系统的物质实体,计算机基础-(-第1次-).pdf

计算机基础 -(- 第 1 次-)第 1 次作业一、填空题(本大题共 30 分&#xff0c;共 10 小题&#xff0c;每小题 3 分)1. 二进制数求积 011 ______ 。2. 计算机系统是由 _ ______ 和 ______ _ 两大部分组成的。3. 八个二进制位称为一个 ______ &#xff0c;是计算机的最小存储单元。…

JS判断数字/字母/中文

原文链接&#xff1a;http://tieba.baidu.com/f?kz140213674 1JS判断数字/字母/中文 1. var reg /^(\w|[\u4E00-\u9FA5])*$/; if(arrusername.match(reg)) { ti1; return ture; } else { alert("用户名只允许为英文&#xff0c;数字和汉字的混合,\n请检查是否前后有…

【转】10个推荐的 PACS/DICOM Server开源项目

10个推荐的 PACS/DICOM Server开源项目 转自&#xff1a;https://zhuanlan.zhihu.com/p/65437040 soolaugust 喜欢我的分享可以关注公众号&#xff1a;雨夜随笔 35 人赞同了该文章 本文仅授权给公众号&#xff1a;雨夜随笔&#xff0c; 欢迎关注 本文翻译自&#xff1a;To…

字节序、位序

字节序 字节序&#xff0c;又称端序、尾序&#xff0c;英文单词为Endian&#xff0c;该单词来源于于乔纳森斯威夫特的小说《格列佛游记》&#xff0c;小说中的小人国因为吃鸡蛋的问题而内战&#xff0c;战争开始是由于以下的原因&#xff1a;我们大家都认为&#xff0c;吃鸡蛋前…

怎么抓取屏幕截图计算机考试时间,定时抓屏快照(电脑截屏工具)V4.8 最新版

定时抓屏快照(电脑截屏工具)是一款非常实用的电脑屏幕定时抓拍软件。想定时截取电脑屏幕&#xff1f;定时抓屏快照(电脑截屏工具)轻松帮助用户。马上要放假了&#xff0c;家长一定很担心小孩最新的上网情况&#xff0c;看是在电脑上玩什么&#xff0c;用户通过该软件可以及时了…

什么是IIS

IIS的设计目的是建立一套集成的服务器服务&#xff0c;用以支持HTTP&#xff0c;FTP和SMTP&#xff0c;它能够提供快速且集成了现有产品&#xff0c;同时可扩展的Internet服务器。IIS相应性极高&#xff0c;同时系统资源的消耗也是最少&#xff0c;IIS的安装&#xff0c;管理和…

【转】C#检查键盘大小写锁定状态的方法

转自&#xff1a; 本文实例讲述了C#检查键盘大小写锁定状态的方法。分享给大家供大家参考。具体分析如下&#xff1a; 1、命名空间&#xff1a; 1 using System.Runtime.InteropServices; 2、导入方法 1 2 [DllImport("user32.dll", EntryPoint "GetKeybo…

计算机系统的备份与还原实验报告,数据库《数据备份与还原》实验报告.doc

《数据库《数据备份与还原》实验报告.doc》由会员分享&#xff0c;提供在线免费全文阅读可下载&#xff0c;此文档格式为doc&#xff0c;更多相关《数据库《数据备份与还原》实验报告.doc》文档请在天天文库搜索。1、&#xfeff;xx大学计算机与信息技术学院实验报告姓 名学 号…

jquery智能提示

中文提示文件http://code.google.com/p/csm-ui/downloads/list aspx页面编写时候<script src"http://www.cnblogs.com/Scripts/jquery-1.3.2.min.js" type"text/javascript"></script><script src"http://www.cnblogs.com/Scripts/jqu…

【转】matlab函数编译成dll供Cpp调用的方法

转自&#xff1a;https://www.cnblogs.com/vincenzo/archive/2009/09/09/1563467.html 以前做过matlab7与c的混合编程&#xff1a;将m函数编译成dll给C调用&#xff0c;从而加快开发的进度。但是今天在matlab2008b下面又做了一遍&#xff0c;发现matlab又改了很多东西&#xf…

可以测试流放之路伤害的软件,测试平台及细节一览 - 《流放之路》国服硬件需求测试:低配也能续写ARPG传奇 - 超能网...

测试平台、场景说明测试平台测试平台配置主要分为两套&#xff0c;第一套配置为Skylake平台基础搭建的ASUS MAXIMUS VIIIGEN(Z170)主板&#xff0c;处理器为Intel Core i7-6700K&#xff0c;内存是G.Skill Ripjaws V 4GB DDR43200x2组成的双通道&#xff1b;第二套配置为Kaveri…