private boolean test(String json) throws Exception {
try {
String serviceUrl = "http://ip:port/nws/services/MobileService";
String function = "getMessage";
Object[] requestParam = new Object[] { json };
RPCServiceClient serviceClient = new RPCServiceClient();
// 指定调用WebService的URL
EndpointReference targetEPR = new EndpointReference(serviceUrl);
Options options = serviceClient.getOptions();
options.setTo(targetEPR);
options.setProperty(HTTPConstants.CHUNKED, false);
// 指定方法返回值的数据类型的Class对象
Class[] responseParam = new Class[] { String.class };
// 指定要调用的getGreeting方法及WSDL文件的命名空间
QName requestMethod = new QName("http://webservices.com", function);
// 调用方法并输出该方法的返回值
String result = (String) serviceClient.invokeBlocking(requestMethod, requestParam, responseParam)[0];
System.out.println(result); // 返回的xml
JSONObject jsonObject = JSONObject.fromObject(result);
System.out.println(jsonObject.getJSONArray("resultlist").getJSONObject(0).getString("Aae100"));
// if (jsonObject.getString("success").equalsIgnoreCase("true")){
// System.out.println("短信发送成功:"+jsonObject.getString("message")+",发送结果:"+jsonObject.getString("results"));
// return true;
// }else{
// System.out.println("短信发送失败,"+jsonObject.getString("message"));
// return false;
// }
return false;
} catch (AxisFault e) {
e.printStackTrace();
return false;
}
}
public static void main(String[] args) throws MalformedURLException, RemoteException{
String json = "{'Aae135':'1234567890','Aae005':'123','TradeCode':'10007'}";
try {
new WebService().test(json);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
众所周知,axis2需要加入大量的jar包,非常不便。笔者经过测试,剔除了大部分不需要的jar,留下这五个是必须的。以上是测试代码,在本机跑过没问题。
下面是五个jar包依赖:
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>1.6.2</version>
</dependency>