网上看到说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 {
/**
* @param args
*/
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]);
}
}
}