-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebSvrClient.java
More file actions
61 lines (43 loc) · 1.43 KB
/
WebSvrClient.java
File metadata and controls
61 lines (43 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package test;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.utils.StringUtils;
import javax.xml.rpc.ServiceException;
import java.net.MalformedURLException;
/**
* Created by zhangqq on 2016/8/29.
*/
public class WebSvrClient {
public static void main(String[] args) {
String url = "http://localhost:8080//services/example/HelloWorld";
String method = "sayTitle";
String[] parms = new String[]{"abc"};
WebSvrClient webClient = new WebSvrClient();
String svrResult = webClient.CallMethod(url, method, parms);
System.out.println(svrResult);
}
public String CallMethod(String url, String method, Object[] args) {
String result = null;
if(StringUtils.isEmpty(url))
{
return "url地址为空";
}
if(StringUtils.isEmpty(method))
{
return "method地址为空";
}
Call rpcCall = null;
try {
//实例websevice调用实例
Service webService = new Service();
rpcCall = (Call) webService.createCall();
rpcCall.setTargetEndpointAddress(new java.net.URL(url));
rpcCall.setOperationName(method);
//执行webservice方法
result = (String) rpcCall.invoke(args);
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}