Search code examples
androidweb-serviceswsdlksoap2

Using wsdl 1.2 with ksoap2-android


I am using ksaop2-android to generate my web service, and here is the wsdl i use: http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL

This is my code:

    String serviceUrl = "http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL";
    String methodName = "GetCityWeatherByZIP";
    SoapObject request = new SoapObject("http://ws.cdyne.com/WeatherWS/",
            methodName);
    request.addProperty("ZIP", "64101");
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER12);
    envelope.dotNet = false;
    envelope.setOutputSoapObject(request);
    HttpTransportSE ht = new HttpTransportSE(serviceUrl);
    try {
        ht.call("http://wsf.cdyne.com/WeatherWS/Weather.asmx/GetCityWeatherByZIP", envelope);
        if (envelope.getResponse() != null) {
            SoapObject soapObject = (SoapObject) envelope.getResponse();
            System.out.println(soapObject.getProperty("ResponseText"));
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (XmlPullParserException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

I can get correct response by this url: http://wsf.cdyne.com/WeatherWS/Weather.asmx/GetCityWeatherByZIP?ZIP=64101

However, my code give me the response like this:

City could not be found in our weather data. Please contact CDYNE for more Details.

It seems the argument was not been sent, which part could be wrong?


Solution

  •    SoapObject request = new SoapObject(NAMESPACE, METHOD);
    
        request.addProperty("ZIP", "64101");
    
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
                SoapEnvelope.VER12);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
    
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    
        try {
            androidHttpTransport.call(SOAP_ACTION, envelope);
            .....
    
    
        } catch (Exception e) {
            e.printStackTrace();
    
        }
    

    where

    SOAP_ACTION = "http://ws.cdyne.com/WeatherWS/GetCityForecastByZIP";
    URL = "http://wsf.cdyne.com/WeatherWS/Weather.asmx";
    METHOD = "GetCityForecastByZIP";
    NAMESPACE = "http://ws.cdyne.com/WeatherWS/";