天天看點

解決Axis2 伺服器端與用戶端 複合參數傳遞問題

網上看到說Axis2伺服器端與用戶端傳遞參數隻支援數組和對象,但是想借助list傳遞多個參數,或參數不固定時,需轉換成OMElement格式傳遞,我試了很多遍沒成功。

是以自己想到辦法,先将多個參數放到list中,到送出時,将list中的參數取出來放到數組中,能過數組進行傳遞,友善,快捷!

下面看代碼

服務端:

public class UCallWsInterface {

// 測試連接配接

public String ConnectionCheck() {

String str = "連接配接成功";

return str;

}

// 業務功能

public CSPActionRes CSPAction(CSPActionReq actionReq) {

//加載xml檔案中的内容

// XMLToBean ActionCmdbean = new XMLToBean();

// List<ActionCmd> actionList = ActionCmdbean.getActionCmd();

CSPActionRes actionRes = new CSPActionRes();

String ActionCmd = actionReq.getActionCmd();

List<String> OutParamList = new ArrayList<String>();

if("CheckSmartcard".equals(ActionCmd))

{

actionRes.setActionCmd("CheckSmartcard");

actionRes.setReturnCode("0");

actionRes.setReturnMsg("成功!");

String OutParam1 = "111";

String OutParam2 = "222";

String OutParam3 = "333";

OutParamList.add(OutParam1);

OutParamList.add(OutParam2);

OutParamList.add(OutParam3);

}

String [] OutParamArray = new String[OutParamList.size()];

for(int i=0;i<OutParamList.size();i++)

{

OutParamArray[i] = OutParamList.get(i);

}

actionRes.setOutParam(OutParamArray);

        return actionRes;

}

}

用戶端:

public class TestClent {

public static void main(String[] args) throws Exception{

// TODO Auto-generated method stub

UCallWsWebStub stub = new UCallWsWebStub();

UCallWsWebStub.CSPAction csp = new UCallWsWebStub.CSPAction();

UCallWsWebStub.CSPActionReq req = new UCallWsWebStub.CSPActionReq();

List<String> InParamList = new ArrayList<String>();

req.setActionCmd("CheckSmartcard");

String InParam1 = "aaa";

String InParam2 = "bbb";

String InParam3 = "ccc";

InParamList.add(InParam1);

InParamList.add(InParam2);

InParamList.add(InParam3);

String [] InParamArray = new String[InParamList.size()];

for(int i=0;i<InParamList.size();i++)

{

InParamArray[i] = InParamList.get(i);

}

req.setInParam(InParamArray);

csp.setActionReq(req);

CSPActionRes res = stub.CSPAction(csp).get_return();

String ActionCmd = res.getActionCmd();

String [] OutParam = res.getOutParam();

System.out.println("---ActionCmd---"+ActionCmd);

System.out.println("---ReturnCode---"+res.getReturnCode());

System.out.println("---ReturnMsg---"+res.getReturnMsg());

for(int i=0;i<OutParam.length;i++)

{

System.out.println("---OutParam"+i+"--"+OutParam[i]);

}

}

}

繼續閱讀