使用wsdl 1.2和ksoap2-android

时间:2013-02-03 13:43:37

标签: android web-services wsdl ksoap2

我正在使用ksaop2-android来生成我的网络服务, 这是我使用的wsdl: http://wsf.cdyne.com/WeatherWS/Weather.asmx?WSDL

这是我的代码:

    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();
    }

我可以通过此网址获得正确答案: http://wsf.cdyne.com/WeatherWS/Weather.asmx/GetCityWeatherByZIP?ZIP=64101

但是,我的代码给了我这样的回复:

在我们的天气数据中找不到城市。请联系CDYNE了解更多详情。

似乎这个论点没有被发送,哪一部分可能是错的?

2 个答案:

答案 0 :(得分:2)

   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();

    }

其中

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

答案 1 :(得分:0)

试试这个:

ht.call("http://ws.cdyne.com/WeatherWS/GetCityWeatherByZIP", envelope);

而不是:

ht.call("http://wsf.cdyne.com/WeatherWS/Weather.asmx/GetCityWeatherByZIP", envelope);