我正在尝试调用此Web服务的方法getWeather():http://www.webservicex.com/globalweather.asmx?WSDL
这是我的代码:
public class ServiceCall {
private static final String NAMESPACE = "http://www.webserviceX.NET";
private static final String URL = "http://www.webservicex.com/globalweather.asmx";
public String prova(String citta){
final String SOAP_ACTION = "http://www.webserviceX.NET/GetWeather";
final SoapObject requestObject=new SoapObject(NAMESPACE,"GetWeather");
PropertyInfo pi = new PropertyInfo();
pi.setName("CityName");
pi.setValue(citta);
pi.setType(String.class);
requestObject.addProperty(pi);
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
Marshal floatMarshal = new MarshalFloat();
floatMarshal.register(envelope);
envelope.setOutputSoapObject(requestObject);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
String res="";
try{
androidHttpTransport.call(SOAP_ACTION, envelope);
SoapObject response = (SoapObject)envelope.bodyIn;
res=response.getPropertyAsString("Body");
}catch(Exception e){Log.d("Prova",e.toString());}
Log.d("Prova", res);
return res;
}
}
但是我得到了这个异常:java.io.IOException:HTTP请求失败,HTTP状态:500
我哪里错了?
答案 0 :(得分:0)
private static final String NAMESPACE = "http://www.webserviceX.NET";
应为private static final String NAMESPACE = "http://www.webserviceX.com";
和final String SOAP_ACTION = "http://www.webserviceX.NET/GetWeather";
应为final String SOAP_ACTION = "http://www.webserviceX.com/GetWeather";
如果我弄错了,请告诉我。