//axis调用webservice不同参数的方法总结
// 调用输入参数是String,返回参数是String的webservice
private static boolean doString(){
String endpoint = "http://localhost:24781/WebService1.asmx?wsdl";
Service service = new Service();
try {
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
call.setOperationName(new QName("http://tempuri.org/","HelloWorld"));//WSDL里面描述的接口名称
call.addParameter(new QName("http://tempuri.org/","s"), org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(org.apache.axis.encoding.XMLType.XSD_STRING);//设置返回类型
call.setSOAPActionURI("http://tempuri.org/HelloWorld");//WSDL里面描述的接口名称
String results = (String)call.invoke(new Object[]{"12,22"});
System.out.println(results);
}catch (Exception e) {
System.err.println(e.toString());
}
return true;
}
// 调用输入参数是String[],返回参数是String的webservice
private static boolean doStringArrayIn(){
String endpoint = "http://localhost:24781/WebService1.asmx?wsdl";
Service service = new Service();
try {
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
call.setOperationName(new QName("http://tempuri.org/","HelloWorld"));//WSDL里面描述的接口名称
org.apache.axis.description.OperationDesc oper;
org.apache.axis.description.ParameterDesc param;
oper = new org.apache.axis.description.OperationDesc();
oper.setName("HelloWorld");
param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName("http://tempuri.org/",
"s"), org.apache.axis.description.ParameterDesc.IN,
new javax.xml.namespace.QName("http://tempuri.org/", "ArrayOfString"),
java.lang.String[].class, false, false);
param.setItemQName(new javax.xml.namespace.QName("http://tempuri.org/", "string"));
oper.addParameter(param);
oper.setReturnType(new javax.xml.namespace.QName("http://www.w3.org/2001/XMLSchema", "string"));
oper.setReturnClass(java.lang.String.class);
call.setOperation(oper);
call.setSOAPActionURI("http://tempuri.org/HelloWorld");//WSDL里面描述的接口名称
String[] temps=new String[]{"11","22"};
String results = (String)call.invoke(new Object[]{temps});
System.out.println(results);
} catch (Exception e) {
System.err.println(e.toString());
}
return true;
}
// 调用输入参数是String,返回参数是String[]的webservice
private static boolean doStringArrayOut(){
String endpoint = "http://localhost:24781/WebService1.asmx?wsdl";
Service service = new Service();
try {
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(endpoint);
call.setOperationName(new QName("http://tempuri.org/","HelloWorld"));//WSDL里面描述的接口名称
QName qn=new QName("http://tempuri.org/","ArrayOfString");
call.registerTypeMapping(String[].class, qn, new ArraySerializerFactory(),
new ArrayDeserializerFactory());
call.addParameter(new QName("http://tempuri.org/","s"), org.apache.axis.encoding.XMLType.XSD_STRING,
javax.xml.rpc.ParameterMode.IN);
call.setReturnType(qn);//设置返回类型
call.setSOAPActionURI("http://tempuri.org/HelloWorld");//WSDL里面描述的接口名称
String[] results = (String[])call.invoke(new Object[]{"12,22"});
System.out.println(results[0]);
}catch (Exception e) {
System.err.println(e.toString());
}
return true;
}