xfire客户端对返回list很挑剔,所以需要使用泛型。
xfire+webservice(客户端调用篇)
服务接口,就是用来调用的,所以客户端显得尤为重要,xfire客户端对返回list很挑剔,所以需要使用泛型。
如何建立webservice client
步骤1,建立webservice project
下一步
下一步,默认
选择xfire包
finish, 这样,webservice项目就完成了
接下来是如何进行客户端开发.
在项目中右键,new webservice client
接着,选择你服务文件,wsdl
完成。
这样在你的项目中,会根据wsdl服务文件,生成客户端所需要的内容。
自动生成文件,下去就细细体会,给出一个测试代码
- 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 endpoint
- IWebservicePortType 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);
- }
- }
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很挑剔,所以需要使用泛型。相关推荐
- xfire客户端获取xcf服务端接口解析问题
1.java.lang.ClassCastException: org.apache.xerces.dom.DocumentImpl cannot be cast to java.lang.Strin ...
- Tencent APIJSON 零代码、全功能、强安全 ORM 库 后端接口和文档零代码,前端(客户端) 定制返回 JSON 的数据和结构
项目介绍 零代码.全功能.强安全 ORM 库 后端接口和文档零代码,前端(客户端) 定制返回 JSON 的数据和结构. A JSON Transmission Protocol and an ORM ...
- springboot上传文件过大,全局异常捕获,客户端没有返回值
springboot上传文件过大,全局异常捕获,客户端没有返回值 参考文章: (1)springboot上传文件过大,全局异常捕获,客户端没有返回值 (2)https://www.cnblogs.co ...
- 服务器共享文件搜索慢的原因,客户端访问服务器共享文件反应很慢.doc
文档介绍: windows2003域中,客户端访问服务器共享文件,反应很慢 windows2003组建的域,全部使用xp作为客户端,其他的电脑访问服务器上的共享文件都很快,只有一台反应明显延时.请问是 ...
- xfire客户端调用服务端报错 XFireRuntimeException: Could not invoke service.. Server returned error code = 4ji
xfire客户端调用xfire服务端报错 org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Server ...
- python自动化客户端_如何使用Python自动化登录客户端,pywinauto确实很强大
工作中会遇见很多重复性的工作,如何让自己懒一点,可以不用每天去做这些,而是去自动化完成一些市场呢? 首先,我们需要登录客户端,如plsql.qq.邮箱.钉钉等等,网上百度过很多方法,发现都是已txt文 ...
- java xfire 客户端代码_java调用xfire webService服务客户端代码
java技术调用xfire webService服务客户端代码 import类: import java.net.MalformedURLException; import java.net.URL; ...
- java ftp限速_为什么Java FTP客户端的传输速率存在很大差异
也许有人可以回答我这个问题.在我最近的工作中,我注意到我的应用程序(通过FTP下载更新)在与 Linux一起使用时非常慢.我在Mac上开发这些东西,所以我之前没有注意到这个问题,因为Mac OS下的下 ...
- Maximo中调用XFire客户端的实现—Weblogic中间件
2019独角兽企业重金招聘Python工程师标准>>> 1.在Maximo工程中创建com.test.webservice包. 2.保存将http://test:8080/test/ ...
最新文章
- 宽度优先遍历(BFS)
- 类 求数组最大最小平均
- sklearn MLP(多层感知机、Multi-layer Perceptron)模型使用RandomSearchCV获取最优参数及可视化
- nginx FastCGI错误Primary script unknown解决办法
- BZOJ 2287 【POJ Challenge】消失之物
- Android基于回调的事件处理
- 逆向工程核心原理学习笔记(十四):栈帧1
- Tech·Ed 2009
- 13.表格标签及其应用实例
- oracle em配置报错,oracle em 启动报错OC4J Configuration issue
- Python调用Java代码部署及初步使用
- Android ListView下拉刷新时卡的问题解决小技巧
- VMware HA实战攻略之一软硬件环境准备
- JavaScript HTML DOM 1
- 程序员的每个阶段,都应该需要思考自己要什么?
- Java ConcurrentHashMap
- linux 使用 ioctl 参数
- 安泰测试新手教程-泰克数字示波器使用方法
- html5 在线抽奖,HTML5大转盘抽奖特效代码
- Win7系统怎么开启远程桌面?Win7远程桌面怎么用
热门文章
- 做最好的自己——读书笔记
- linux 定时备份mysql数据库
- MVC + LigerUI 做后台管理还真是清爽
- C# 淘宝商品微信返利助手开发-(三)返利助手开发(1)API介绍
- excel按季度分类汇总_Excel数据分析实战(1)--电商销售记录分析
- 第8章-常用优先级和css3
- 教你配置支付宝应用网关和授权回调地址
- python3 venv 虚拟环境使用
- 2020计算机领域前沿热门技术,CFP: ICPCSEE 2020 (SCI or EI Indexd) 第6届国际计算机前沿大会...
- java spring注入 静态方法_java相关:spring为类的静态属性实现注入实例方法