我正在使用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,如果它有一些错误,那只是来自我的复制(并删除了那些不需要的部分)。
那么,为什么我会收到上述错误?