当前位置 : 主页 > 编程语言 > c++ >

调用部分webservice工具方法

来源:互联网 收集:自由互联 发布时间:2021-07-03
WsUtil public class WsUtil { public static String callService(String wsdlUrl, String actionURI, Map paramMap) { Object[] params = null; int index = actionURI.lastIndexOf("/") + 1; String action = actionURI.substring(index); String nameSpace
WsUtil
public class WsUtil {

    public static String callService(String wsdlUrl, String actionURI,
                                    Map
 
   paramMap) {
        Object[] params = null;
        int index = actionURI.lastIndexOf("/") + 1;
        String action = actionURI.substring(index);
        String nameSpaceUri = actionURI.substring(0,index);
        try {
            org.apache.axis.client.Service service = new org.apache.axis.client.Service();
            Call call = (Call) service.createCall();
            call.setTargetEndpointAddress(wsdlUrl);
            call.setSOAPActionURI(actionURI);
            call.setOperationName(new QName(nameSpaceUri, action));
            for (String key : paramMap.keySet()) {
                call.addParameter(key, XMLType.XSD_STRING, ParameterMode.IN);
            }
            if (paramMap.size() > 0) {
                params = paramMap.values().toArray();
            }
            call.setReturnType(XMLType.XSD_STRING);// 返回值类型:String
            String re = (String) call.invoke(params);
            return re;
        } catch (Exception e) {
            return e.toString();
        }
    }
}
 
上一篇:Android 文件上传
下一篇:ShortcutBuilder
网友评论