81,091
社区成员
发帖
与我相关
我的任务
分享
package com.axis;
import javax.xml.namespace.QName;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;
public class Test {
private static final String wsdl = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx";
private static final String namespace="http://WebXml.com.cn";
public static String[] testWeather(String theCityName){
String[] result=null;
try {
RPCServiceClient serviceClient = new RPCServiceClient();
Options options = serviceClient.getOptions();
EndpointReference targetEPR = new EndpointReference(wsdl);
options.setAction(namespace+"/getWeatherbyCityName");
options.setTo(targetEPR);
//options.setTransportInProtocol(Constants.TRANSPORT_HTTP);
// options.setProperty(HTTPConstants.CHUNKED, "false");//设置不受限制.
// options.setProperty(HTTPConstants.PROXY, buildProxy());
// options.setProperty(Constants.Configuration.HTTP_METHOD,HTTPConstants.HTTP_METHOD_POST);
Object[] arg = new Object[]{theCityName}; // 复杂参数
Class[] classes = new Class[]{String.class};
QName opName = new QName(namespace,"getWeatherbyCityName");
result = (String[])serviceClient.invokeBlocking(opName,arg,classes)[0];
if (result != null){
return result;
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO 自动生成方法存根
String[] weather = testWeather("58367");
for(String w : weather){
System.out.println(w);
}
}
}