KSoap-Android:意外的子元素 x,x 是预期的
我正在使用 KSoap for Android,并且遇到以下问题:我调用 Web 服务,收到以下错误消息:
SoapFault - faultcode: 'axis2ns5:Client.input.missingOrUnexpectedParameter'
faultstring:
'Unexpected subelement site, site is expected(
callId: 34527, Client.input.missingOrUnexpectedParameter/1.2.2)'
faultactor: 'null' detail: org.kxml2.kdom.Node@7e5db5ae
这是我的请求代码:
SoapObject request = new SoapObject("http://example.com/namespace", "MyService");
request.addProperty("site", "example.org");
request.addProperty("user", "123");
request.addProperty("password", "456");
List<HeaderProperty> headerProperties = new LinkedList<HeaderProperty>();
headerProperties.add(new HeaderProperty("Authorization", "Basic " + org.kobjects.base64.Base64.encode("user:pass".getBytes())));
HttpsTransportSE con = new HttpsTransportSE("example.com", 443, "/myWebService/", 10000);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
con.call("login", envelope, headerProperties);
System.out.println(envelope.bodyIn);
不要介意我在站点参数和 URI 中放入的值。
这是我的 WSDL(至少是与登录有关的部分):
<wsdl:definitions name="MyService" targetNamespace="http://example.com/namespace" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://example.com/namespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<wsdl:types>
<xsd:schema targetNamespace="http://example.com/namespace">
<xsd:element name="loginRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="site" type="xsd:string"/>
<xsd:element name="user" type="xsd:string"/>
<xsd:element name="password" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="loginResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="successful" type="xsd:boolean"/>
<xsd:element minOccurs="0" name="sessionToken" type="xsd:string"/>
<xsd:element minOccurs="0" name="firstTimeUser" type="xsd:boolean"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<!-- Snip -->
<wsdl:message name="loginRequest">
<wsdl:part name="parameters" element="tns:loginRequest">
</wsdl:part>
</wsdl:message>
<wsdl:message name="loginResponse">
<wsdl:part name="parameters" element="tns:loginResponse">
</wsdl:part>
</wsdl:message>
<!-- Snip -->
<wsdl:operation name="login">
<wsdl:input message="tns:loginRequest">
</wsdl:input>
<wsdl:output message="tns:loginResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:binding name="MyServiceSOAP" type="tns:MyService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="login">
<soap:operation soapAction="http://example.com/namespace/login"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
</wsdl:definitions>
我没有编写 WSDL,如果其中存在一些错误,那只是来自我的复制(并删除了与登录无关的部分)这个问题)。
那么,为什么我会收到上述错误?
I am using KSoap for Android, and I'm having the following problem: When I call the web service, I get the following error message:
SoapFault - faultcode: 'axis2ns5:Client.input.missingOrUnexpectedParameter'
faultstring:
'Unexpected subelement site, site is expected(
callId: 34527, Client.input.missingOrUnexpectedParameter/1.2.2)'
faultactor: 'null' detail: org.kxml2.kdom.Node@7e5db5ae
This is my request code:
SoapObject request = new SoapObject("http://example.com/namespace", "MyService");
request.addProperty("site", "example.org");
request.addProperty("user", "123");
request.addProperty("password", "456");
List<HeaderProperty> headerProperties = new LinkedList<HeaderProperty>();
headerProperties.add(new HeaderProperty("Authorization", "Basic " + org.kobjects.base64.Base64.encode("user:pass".getBytes())));
HttpsTransportSE con = new HttpsTransportSE("example.com", 443, "/myWebService/", 10000);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
con.call("login", envelope, headerProperties);
System.out.println(envelope.bodyIn);
Never mind the values I put in the site parameter and the URI.
This is my WSDL (at least the parts concerned for the login):
<wsdl:definitions name="MyService" targetNamespace="http://example.com/namespace" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://example.com/namespace" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<wsdl:types>
<xsd:schema targetNamespace="http://example.com/namespace">
<xsd:element name="loginRequest">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="site" type="xsd:string"/>
<xsd:element name="user" type="xsd:string"/>
<xsd:element name="password" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="loginResponse">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="successful" type="xsd:boolean"/>
<xsd:element minOccurs="0" name="sessionToken" type="xsd:string"/>
<xsd:element minOccurs="0" name="firstTimeUser" type="xsd:boolean"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:schema>
</wsdl:types>
<!-- Snip -->
<wsdl:message name="loginRequest">
<wsdl:part name="parameters" element="tns:loginRequest">
</wsdl:part>
</wsdl:message>
<wsdl:message name="loginResponse">
<wsdl:part name="parameters" element="tns:loginResponse">
</wsdl:part>
</wsdl:message>
<!-- Snip -->
<wsdl:operation name="login">
<wsdl:input message="tns:loginRequest">
</wsdl:input>
<wsdl:output message="tns:loginResponse">
</wsdl:output>
</wsdl:operation>
<wsdl:binding name="MyServiceSOAP" type="tns:MyService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="login">
<soap:operation soapAction="http://example.com/namespace/login"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
</wsdl:definitions>
I didn't write the WSDL, and if there are some errors in it, that just comes from my copying (and removing the parts that don't have to with this question).
So, why am I getting the above error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了消除该错误,我需要取消注释
envelope.dotNet = true
,如 this 所建议的那样a> 答案。在其他一些问题中建议将其设置为 true 。To eliminate the error, I needed to un-comment
envelope.dotNet = true
, as suggested by this answer. Setting it to true was suggested in some other question.