|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 |
public static long TIMEOUTINMILLISECONDS=100000;/** * 调用webservice * @param url webserviceURL * @param methodName 调用方法名 * @param namespace 命名空间 * @param params 参数 * @param returnTypes 返回参数类型 * @return * @throws AxisFault */public
static <T> Object[] invokeMethod(String url,String methodName,String namespace,Object[] params,Class<T>[] returnTypes) throws
AxisFault{ RPCServiceClient client=new
RPCServiceClient(); Options options=client.getOptions(); EndpointReference epr=new
EndpointReference(url); options.setTo(epr); options.setTimeOutInMilliSeconds(TIMEOUTINMILLISECONDS); QName qName=new
QName(namespace, methodName); Object[] results=client.invokeBlocking(qName, params, returnTypes); return
results;} |
调用方法
1、传递单个参数
|
1 |
Object[] objs = invokeMethod("http://localhost:8080/axis2/services/MobileWs", "getArrayTest", "http://ws.apache.org/axis2", new
Object[] {"zhangsan"}, new
Class[]{String.class}); |
2、传递数组
|
1 |
Object[] objs = invokeMethod("http://localhost:8080/axis2/services/MobileWs", "getArrayTest", "http://ws.apache.org/axis2", new
Object[] {new
String[]{"zhangsan","lisi"}}, new
Class[]{String.class}); |
原文:http://www.cnblogs.com/Laupaul/p/3564224.html