@Test
public void testGetWeather() {
String url = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx";//
Service service = new Service();
Call call;
try {
call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(url));
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://WebXml.com.cn/getWeatherbyCityName");
call.setOperationName(new QName("http://WebXml.com.cn/",
"getWeatherbyCityName"));
call.addParameter(
new QName("http://WebXml.com.cn/", "theCityName"),
org.apache.axis.encoding.XMLType.XSD_STRING,
ParameterMode.IN);
call.setReturnType(new QName("http://WebXml.com.cn/",
"getWeatherbyCityNameResponse"), String[].class);
/**
// QName Xliginfo = new QName("http://WebXml.com.cn/",
// "getWeatherbyCityNameResult");
// call.registerTypeMapping(String.class, Xliginfo,
// new BeanSerializerFactory(String.class, Xliginfo),
// new BeanDeserializerFactory(String.class, Xliginfo));
String[] result = (String[]) call.invoke(new Object[] { "南京" });
for (String str : result) {
System.out.println(str);
}
return;
} catch (Exception e) {
e.printStackTrace();
return;
}
}
public void testGetWeather() {
String url = "http://www.webxml.com.cn/WebServices/WeatherWebService.asmx";//
Service service = new Service();
Call call;
try {
call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(url));
call.setUseSOAPAction(true);
call.setSOAPActionURI("http://WebXml.com.cn/getWeatherbyCityName");
call.setOperationName(new QName("http://WebXml.com.cn/",
"getWeatherbyCityName"));
call.addParameter(
new QName("http://WebXml.com.cn/", "theCityName"),
org.apache.axis.encoding.XMLType.XSD_STRING,
ParameterMode.IN);
call.setReturnType(new QName("http://WebXml.com.cn/",
"getWeatherbyCityNameResponse"), String[].class);
/**
*因为String 是简单类型并不需要封装
若要封装可以去掉注释
*/// QName Xliginfo = new QName("http://WebXml.com.cn/",
// "getWeatherbyCityNameResult");
// call.registerTypeMapping(String.class, Xliginfo,
// new BeanSerializerFactory(String.class, Xliginfo),
// new BeanDeserializerFactory(String.class, Xliginfo));
String[] result = (String[]) call.invoke(new Object[] { "南京" });
for (String str : result) {
System.out.println(str);
}
return;
} catch (Exception e) {
e.printStackTrace();
return;
}
}