2013-05-01 136 views
0

我試圖調用此WebService的方法的GetWeather()一個簡單的Web服務方法:http://www.webservicex.com/globalweather.asmx?WSDL安卓:調用使用kso​​ap2

這裏是我的代碼:

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
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";

讓我知道,如果我錯了。

相關問題