gpt4 book ai didi

android - KSOAP2 和 WSDL 返回解码错误 : unexpected element

转载 作者:行者123 更新时间:2023-11-30 01:46:03 27 4
gpt4 key购买 nike

我试图了解如何使用 a SOAP webservice (link to wsdl)与安卓系统。我有这个简单的方法,使用带有依赖项 jar 的 ksoap2 3.0:

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 的结果?

最佳答案

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

这是因为预期的命名空间必须是一个空字符串。因此,在将您的属性添加到请求时,请确保将“”放入命名空间。

您可能还想在创建请求之前添加线程策略。

    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);

SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME);
Request.addProperty("", "elementCd","WTEQ");

关于android - KSOAP2 和 WSDL 返回解码错误 : unexpected element,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33706269/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com