KSOAP2和WSDL返回解组错误:意外元素

问题描述 投票:1回答:1

我正在尝试了解如何在Android上使用a SOAP webservice (link to wsdl)。我有一个简单的方法,将ksoap2 3.0与依赖项jar一起使用:

public void simpleSoap() {
        String SOAP_ACTION = "";
        String METHOD_NAME = "getElement";
        String NAMESPACE = "http://www.wcc.nrcs.usda.gov/ns/awdbWebService";
        String URL = "http://www.wcc.nrcs.usda.gov/awdbWebService/services?WSDL";

        try {
            SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);

            Request.addProperty("elementCd","WTEQ");

            SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            soapEnvelope.dotNet = true;
            soapEnvelope.setOutputSoapObject(Request);

            HttpTransportSE transport = new HttpTransportSE(URL);

            transport.call(SOAP_ACTION, soapEnvelope);
            resultString = (SoapPrimitive) soapEnvelope.getResponse();

            Log.i(TAG, "Result: " + resultString);
        } catch (Exception ex) {
            Log.e(TAG, "Error: " + ex.getMessage());
        }
    }

每次响应时我都会收到错误/强制关闭:

Error: Unmarshalling Error: unexpected element
(uri:"http://www.wcc.nrcs.usda.gov/ns/awdbWebService",
local:"elementCd"). Expected elements are <{}elementCd>

我已经在wonderful online client上对此进行了测试,并获得了结果。我在这里想念什么?为什么我无法将此硬编码到addProperty函数中的简单elementCd WTEQ得到结果?

android web-services soap ksoap2 android-ksoap2
1个回答
0
投票

[三周后,我偶然发现了这个问题:https://stackoverrun.com/es/q/2805758

这是因为期望的名称空间必须为空字符串。因此,在将属性添加到请求时,只需确保在名称空间中放入“”即可。

Request.addProperty("", "elementCd","WTEQ");
© www.soinside.com 2019 - 2024. All rights reserved.