微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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,null };             Class[] returnClass = new Class[] { LoginResultDTO.class};             // 调用method方法输出方法的返回值             result = serviceClient.invokeBlocking(opAddEntry,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,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,"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,"","01","1",queryInfo};             Class[] returnClass = new Class[] { String.class,Integer.class,String.class,ShineQueryInfo.class};             // 调用method方法输出方法的返回值             result = serviceClient.invokeBlocking(opAddEntry,returnClass);             System.out.println(result[0]);            // etParamInfoList = (List<ParamInfoDTO>)result[0];         } catch (AxisFault e) {             e.printstacktrace();         }     }      }

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐