webservice的axis2客户端调用方式和xfire调用方式

1、axis2调用方式:

package com.shine.fund;

import javax.xml.namespace.QName;

import org.apache.axis2.AxisFault;

import org.apache.axis2.addressing.EndpointReference;

import org.apache.axis2.client.Options;

import org.apache.axis2.rpc.client.RPCServiceClient;

import com.shine.eframe.webapp.bean.BaseBean;

public class TestWS extends BaseBean {

/**

* @param args

* @throws AxisFault

*/

public static void main(String[] args)  {

// TODO Auto-generated method stub

try{

String serviceUrl = "http://127.0.0.1:8080/eospexService/ws/eospexService_UtilFundNavCtrl?wsdl";

// 调用发送

Object[] result;

//使用RPC方式调用WebService

RPCServiceClient serviceClient = new RPCServiceClient();

Options options = serviceClient.getOptions();

EndpointReference targetEPR = new EndpointReference(serviceUrl);

options.setTo(targetEPR);

String sessionId = "22f92a5ff3bf8f45dab6a9190c7bc5a9";

//String sessionId = currentServiceSessionId();

// 指定要调用的method方法及WSDL文件的命名空间

//WSDL文件的命名空间<wsdl:definitions>元素的targetNamespace属性值

QName opAddEntry = new QName("http://ctrl.fund.shine.com/", "getWSResultList");

String date = "20150501";

Object[] params = new Object[] {sessionId ,date  };

Class[] returnClass = new Class[] { String.class};

// 调用method方法并输出该方法的返回值

result = serviceClient.invokeBlocking(opAddEntry, params, returnClass);

System.out.println("111");

System.out.println(result[0]);

}

catch(Exception e){

}

}

}

2、xfire调用方式:

package com.shine.eframe.test;

import java.net.MalformedURLException;

import java.net.URL;

import java.util.List;

import javax.xml.namespace.QName;

import org.apache.axis2.AxisFault;

import org.apache.axis2.addressing.EndpointReference;

import org.apache.axis2.client.Options;

import org.apache.axis2.rpc.client.RPCServiceClient;

import org.codehaus.xfire.client.Client;

import org.codehaus.xfire.client.XFireProxyFactory;

import org.codehaus.xfire.service.Service;

import org.codehaus.xfire.service.binding.ObjectServiceFactory;

import com.shine.eframe.app.right.model.BaseAppInfoDTO;

import com.shine.eframe.esm.dto.LoginResultDTO;

import com.shine.eframe.rightmanage.ctrl.AppInfoCtrl;

import com.shine.eframe.rightmanage.dto.AppInfoDTO;

import com.shine.eframe.rightmanage.dto.ParamInfoDTO;

import com.shine.pub.query.ShineQueryInfo;

import com.shine.pub.query.ShineRowSet;

import com.shine.pub.query.ShineRowSetHelper;

import com.shine.pub.test.BaseSpringTest;

public class XFireTest extends BaseSpringTest {

public String getPackageMsg() {

return "<?xml version=\\\"1.0\\\" encoding=\\\"GB2312\\\"?><ipmp><head><busiCode>20001</busiCode></head><body><settleCode>1</settleCode><timestamp>20141521 03:15:45</timestamp><instructionId>ZLSnull20140121null</instructionId><busiType>40203</busiType><orderingAccount>11001007200059507029</orderingAccount><orderingAccountName>宏源证券股份有限公司</orderingAccountName><orderingOpenBank>建行北京西四支行营业部(支付系统行号:105100003023)</orderingOpenBank><orderingElecBankCode>对方资金开户行联行行号</orderingElecBankCode><orderingCurrency>CNY</orderingCurrency><beneficiaryAccountName>本方账户名称</beneficiaryAccountName><beneficiaryAccount>BFZH0001</beneficiaryAccount><beneficiaryOpenBank>本方开户行</beneficiaryOpenBank><beneficiaryPaySystemId>1234</beneficiaryPaySystemId><beneficiaryElecBankCode>5678</beneficiaryElecBankCode><beneficiaryCurrency>CNY</beneficiaryCurrency><payAmount>150032.88</payAmount><payDate>20120406</payDate><payUsage>卖券080025A100000001</payUsage><remark>卖券080025A100000001</remark></body></ipmp>";

}

public void testCallWs() throws Exception {

try {

// 获取properties中的配置url地址

String serviceUrl = "http://10.168.2.114:8080/EFrameCoreService/ws/EFrameCore_AppInfoCtrl";// 新增

Service serviceModel = new ObjectServiceFactory().create(

AppInfoCtrl.class, null, serviceUrl + "?wsdl", null);

AppInfoCtrl service = (AppInfoCtrl) new XFireProxyFactory()

.create(serviceModel, serviceUrl);

// AppInfoCtrl

AppInfoDTO appInfo = (AppInfoDTO)service.getAppInfo("44faafb34ca91cf4f4a933de6c20942c", 1);

/*XFireProxy proxy = (XFireProxy) Proxy.getInvocationHandler(service);

Client client = proxy.getClient();

// 发送授权信息

client.addOutHandler(new ClientAuthenticationHandler("admin",

"admin"));  */

// 输出调用web services方法的返回信息

System.out.println(appInfo);

} catch (MalformedURLException e) {

e.printStackTrace();

} catch (IllegalArgumentException e) {

e.printStackTrace();

}

}

public void testWs() throws Exception {

try {

// 获取properties中的配置url地址

String serviceUrl = "http://10.168.3.125:8080/EsmService/ws/Esm_ServiceManagerCtrl?wsdl";

Client c = new Client(new URL(serviceUrl));

//OperationInfo op = new OperationInfo;

//c.invoke(op, params)

// AppInfoCtrl

Object[] results = c.invoke("login", new Object[] {null, "TestHost", "11974d21ede5455869e039e14814ff22", null });

/*XFireProxy proxy = (XFireProxy) Proxy.getInvocationHandler(service);

Client client = proxy.getClient();

// 发送授权信息

client.addOutHandler(new ClientAuthenticationHandler("admin",

"admin"));  */

// 输出调用web services方法的返回信息

} catch (MalformedURLException e) {

e.printStackTrace();

} catch (IllegalArgumentException e) {

e.printStackTrace();

}

}

public void testWebservice1() {

/*String userCode = "TestHost";

String password = "11974d21ede5455869e039e14814ff22";

Client client = new Client(new URL("http://127.0.0.1:8123/EsmService/ws/Esm_ServiceManagerCtrl?wsdl"));

Object[] loginParam = { null, userCode, password, null };

Object[] results = client.invoke("login", loginParam);

System.out.println(results);*/

}

public void testCallAppInfo() throws Exception {

// 登录

String sessionId = "e1440c8a9030138d2f44cf60174d9f76";

// 调用

String serviceUrl = "http://10.168.2.56:8123/EFrameCoreService/ws/EFrameCore_AppInfoCtrl?wsdl";

// 调用发送

Object[] result;

result = invokeWsService(sessionId, serviceUrl, "getAppInfo", "http://app.shine.com/eframecore/services",  new Object[] {

sessionId, 1 }, new Class[] { String.class });

System.out.print(result[0]);

}

/**

* 调用服务方法,根据自己的需求进行修改

*

* @param domain 服务域

* @param serviceName 服务名

* @return 方法调用返回值

* @throws Exception

*

*             <pre>

* 修改日期        修改人    修改原因

* 2013-3-17   wuhanchu    新建

* </pre>

*/

private Object[] invokeWsService(String sessionId, String serviceUrl, String mothodName, String namespace,

Object[] param, Class[] returnValueClass) throws Exception {

// 使用RPC方式调用WebService

RPCServiceClient serviceClient = new RPCServiceClient();

Options options = serviceClient.getOptions();

// 指定调用WebService的URL

//        EndpointReference targetEPR = new EndpointReference("http://" + jbossIp + ":" + jbossPort + "/" + domain

//                + "/ws/" + serviceName + "?wsdl");

EndpointReference targetEPR = new EndpointReference(serviceUrl);

options.setTo(targetEPR);

// 指定要调用的method方法及WSDL文件的命名空间

QName opAddEntry = new QName("http://ctrl.eipmp.shine.com/", mothodName);

// 调用method方法并输出该方法的返回值

return serviceClient.invokeBlocking(opAddEntry, param, returnValueClass);

}

public void testInvokeWs() throws AxisFault, InterruptedException {

while(true) {

String serviceUrl = "http://10.168.3.126:8080/EsmService/ws/Esm_ServiceManagerCtrl?wsdl";

// 调用发送

Object[] result;

//使用RPC方式调用WebService

RPCServiceClient serviceClient = new RPCServiceClient();

Options options = serviceClient.getOptions();

EndpointReference targetEPR = new EndpointReference(serviceUrl);

options.setTo(targetEPR);

// 指定要调用的method方法及WSDL文件的命名空间

QName opAddEntry = new QName("http://app.shine.com/", "login");

Object[] params = new Object[] {null, "TestHost", "11974d21ede5455869e039e14814ff22", null };

Class[] returnClass = new Class[] { LoginResultDTO.class};

// 调用method方法并输出该方法的返回值

result = serviceClient.invokeBlocking(opAddEntry, params, returnClass);

System.out.println(result[0]);

Thread.sleep(200);

}

}

public void testInvokeWs1() throws AxisFault {

String serviceUrl = "http://127.0.0.1:8080/EFrameCoreService/ws/EFrameCore_ParamInfoCtrl?wsdl";

// 调用发送

Object[] result;

//使用RPC方式调用WebService

RPCServiceClient serviceClient = new RPCServiceClient();

Options options = serviceClient.getOptions();

EndpointReference targetEPR = new EndpointReference(serviceUrl);

options.setTo(targetEPR);

String sessionId = "c9fe9905cec15d81278c74639da42636";

// 指定要调用的method方法及WSDL文件的命名空间

QName opAddEntry = new QName("http://app.shine.com/", "getParamValueByParamCode");

Object[] params = new Object[] {sessionId, "CAS_FRAME_DEF" };

Class[] returnClass = new Class[] { String.class};

// 调用method方法并输出该方法的返回值

result = serviceClient.invokeBlocking(opAddEntry, params, returnClass);

System.out.println(result[0]);

}

public void testA() {

String serviceUrl = "http://10.168.2.114:8080/EFrameCoreService/ws/EFrameCore_AppInfoCtrl";

Service serviceModel = new ObjectServiceFactory().create(AppInfoCtrl.class, null, "http://10.168.2.114:8080/EFrameCoreService/ws/EFrameCore_AppInfoCtrl?wsdl", null);

XFireProxyFactory serviceFactory = new XFireProxyFactory();

try{

String sessionId = "262b73aacb60eb973e9598552bcd5f5b";

AppInfoCtrl service = (AppInfoCtrl)serviceFactory.create(serviceModel,serviceUrl);

BaseAppInfoDTO appInfo = service.getAppInfo(sessionId, 1);

System.out.println(appInfo.getAppName());

} catch(Exception e){

e.printStackTrace();

}

}

public void testAB() {

List<ParamInfoDTO> etParamInfoList = null;

String serviceUrl = "http://127.0.0.1:8080/EFrameCoreService/ws/EFrameCore_ParamInfoCtrl?wsdl";

// 调用发送

Object[] result;

try{

//使用RPC方式调用WebService

RPCServiceClient serviceClient = new RPCServiceClient();

Options options = serviceClient.getOptions();

EndpointReference targetEPR = new EndpointReference(serviceUrl);

options.setTo(targetEPR);

String sessionId = "262b73aacb60eb973e9598552bcd5f5b";

// 指定要调用的method方法及WSDL文件的命名空间

QName opAddEntry = new QName("http://pub.shine.com/", "queryParamInfo");

ShineQueryInfo queryInfo = new ShineQueryInfo(10);

Object[] params = new Object[] {sessionId, null, "", "01", "1", queryInfo};

Class[] returnClass = new Class[] { String.class, Integer.class, String.class, String.class, String.class, ShineQueryInfo.class};

// 调用method方法并输出该方法的返回值

result = serviceClient.invokeBlocking(opAddEntry, params, returnClass);

System.out.println(result[0]);

// etParamInfoList = (List<ParamInfoDTO>)result[0];

} catch (AxisFault e) {

e.printStackTrace();

}

}

}

时间: 2024-08-02 23:00:48

webservice的axis2客户端调用方式和xfire调用方式的相关文章

C# 调用WebService的3种方式 :直接调用、根据wsdl生成webservice的.cs文件及生成dll C#调用、动态调用

1.直接调用 已知webservice路径,则可以直接 添加服务引用--高级--添加web引用 直接输入webservice URL.这个比较常见也很简单 即有完整的webservice文件目录如下图所示, 也可以在本地IIS根据webservice文件目录新发布一个webservice,然后程序动态调用,修改Url public new string Url { set; get; } 2.根据wsdl文件生成webservice 的.cs文件 及 生成dll C#调用   有时没有这么多文件

Live555 中的客户端动态库.so的调用方式之一 程序中调用

1.  打开动态链接库:    #include <dlfcn.h>    void *dlopen(const char *filename, int flag);    该函数返回操作句柄,如:    void *pHandle = dlopen(strSoFilePath, RTLD_LAZY); 2.  取动态对象地址:    #include <dlfcn.h>    void *dlsym(void *pHandle, char *symbol);    dlsym根据

Java创建WebService服务及客户端实现(转)

简介 WebService是一种服务的提供方式,通过WebService,不同应用间相互间调用变的很方便,网络上有很多常用的WebService服务,如:http://developer.51cto.com/art/200908/147125.htm,不同的语言平台对WebService都有实现,Java的WebService实现,比较流行的有Axis2.Jaxws,本文介绍的是Axis2. Axis2下载和部署 Axis2是Apache开发的一个开源项目,再次感叹Apache的伟大! 下载地址

webservice的Axis2入门教程java版

本文转自百度文库 Axis2是一套崭新的WebService引擎,该版本是对Axis1.x重新设计的产物.Axis2不仅支持SOAP1.1和SOAP1.2,还集成了非常流行的REST WebService,同时还支持Spring.JSON等技术.这些都将在后面的系列教程中讲解.在本文中主要介绍了如何使用Axis2开发一个不需要任何配置文件的WebService,并在客户端使用Java和C#调用这个WebService. 一.Axis2的下载和安装 读者可以从如下的网址下载Axis2的最新版本:

Java创建WebService服务及客户端实现

简介 WebService是一种服务的提供方式,通过WebService,不同应用间相互间调用变的很方便,网络上有很多常用的WebService服务,如:http://developer.51cto.com/art/200908/147125.htm,不同的语言平台对WebService都有实现,Java的WebService实现,比较流行的有Axis2.Jaxws,本文介绍的是Axis2. Axis2下载和部署 Axis2是Apache开发的一个开源项目,再次感叹Apache的伟大! 下载地址

XFire调用CXF参数为Null的问题

最近,领导分配了一个任务,做接口联调.情况是这样,对方客户升级了接口采用CXF,而我们还是用的XFire1.2.6,首先就遇到了这个问题:XFire调用CXF参数为Null的问题 . 在网上搜了一大堆资料: http://blog.csdn.net/larry_lv/article/details/6721057 http://ks2144634.blog.163.com/blog/static/133585503201412855556210/ 按照第一个始终还是没能解决,后来找到第二个花了不

WebService 服务端客户端 实例(一)

Delphi中WebService包含的组件解释(有7个)     (1) THTTPRIO-------:使用Http消息来调用远程使用SOAP的接口对象     (2) THTTPReqResp---:给服务器发送一个SOAP消息, THTTPReqResp在可调用接口上执行一个方法请求.       (3) TOPToSoapDomConvert ----:TOPToSoapDomConvert处理Soap方法请求的组合与分发     (4) TSoapConnection:TSoapCo

命令行中Axis2客户端代码生成

打开CMD,把以下命令运行. set Axis_Lib=E:\J2EE\WebService\lib //设置Axis2 WebService所需要的lib包 set Java_Cmd=java -Djava.ext.dirs=%Axis_Lib% set Output_Path=d:\ //设置客户端代码生成路径 set Package=sendi //设置客户端代码的包名 %Java_Cmd% org.apache.axis.wsdl.WSDL2Java -o%Output_Path% -p

调用DLL的2种方式

[调用DLL的2种方式] DLL在生成的时候会有dll.lib2个文件,另外包含相应的.h. 1.静态方式,通过lib来引用dll,以及引入.h. 2.只通过dll来使用,前提是知道内部的函数符号. 调用DLL的2种方式,布布扣,bubuko.com