加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

解决Axis2 服务器端与客户端 复合参数传递问题

发布时间:2020-12-16 23:42:28 所属栏目:安全 来源:网络整理
导读:网上看到说Axis2服务器端与客户端传递参数只支持数组和对象,但是想借助list传递多个参数,或参数不固定时,需转换成OMElement格式传递,我试了很多遍没成功。 所以自己想到办法,先将多个参数放到list中,到提交时,将list中的参数取出来放到数组中,能过数

网上看到说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]); } } }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读