java代码直接附上,欢迎讨论
public String go(String wsdlURL,String targetNamespace,String methodName,Map<String,Object> param,String soapActionURI) {
String result ="no result!";
try {
String endpoint = wsdlURL;
Service service = new Service();
Call call = (Call)service.createCall();
// 指定调用WebService的URL
call.setTargetEndpointAddress(endpoint);
//设置节点命名空间和对应的方法名
call.setOperationName(new QName(targetNamespace,methodName));
//添加参数和参数的数据类型
Object[] obj = new Object[param.size()];
int i = 0;
for (Map.Entry<String, Object> entry : param.entrySet()) {
String classname = entry.getValue().getClass().getSimpleName();
if("Integer".equals(classname)){
call.addParameter(new QName(targetNamespace, entry.getKey()),XMLType.XSD_INTEGER,javax.xml.rpc.ParameterMode.IN);
}else if("Byte".equals(classname)){
call.addParameter(new QName(targetNamespace, entry.getKey()),XMLType.XSD_BYTE,javax.xml.rpc.ParameterMode.IN);
}else if("Short".equals(classname)){
call.addParameter(new QName(targetNamespace, entry.getKey()),XMLType.XSD_SHORT,javax.xml.rpc.ParameterMode.IN);
}else if("Long".equals(classname)){
call.addParameter(new QName(targetNamespace, entry.getKey()),XMLType.XSD_LONG,javax.xml.rpc.ParameterMode.IN);
}else if("Float".equals(classname)){
call.addParameter(new QName(targetNamespace, entry.getKey()),XMLType.XSD_FLOAT,javax.xml.rpc.ParameterMode.IN);
}else if("Double".equals(classname)){
call.addParameter(new QName(targetNamespace, entry.getKey()),XMLType.XSD_DOUBLE,javax.xml.rpc.ParameterMode.IN);
}else if("Character".equals(classname)){
call.addParameter(new QName(targetNamespace, entry.getKey()),XMLType.XSD_ANYTYPE,javax.xml.rpc.ParameterMode.IN);
}else if("Boolean".equals(classname)){
call.addParameter(new QName(targetNamespace, entry.getKey()),XMLType.XSD_BOOLEAN,javax.xml.rpc.ParameterMode.IN);
}else if("String".equals(classname)){
call.addParameter(new QName(targetNamespace, entry.getKey()),XMLType.XSD_STRING,javax.xml.rpc.ParameterMode.IN);
}
obj[i]=entry.getValue();
i++;
}
//返回的数据类型
call.setReturnType(XMLType.XSD_STRING);
call.setUseSOAPAction(true);
call.setSOAPActionURI(soapActionURI);
//调用
result = call.invoke(obj).toString();
System.out.println(result);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}