所以这是我的问题。我想在Android设备上创建SOAP
客户端,它将与我制作的服务器通信。
我发现唯一可行且最简单的方法是使用kSOAP2
库。我跟着这个例子。这是我的WSDL
:
<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"
xmlns:tns="http://test/ExampleWs.php"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/"
xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
targetNamespace="http://test/ExampleWs.php" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
<wsdl:types>
<s:schema elementFormDefault="qualified" targetNamespace="http://test/ExampleWs.php">
<s:element name="Login">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="login" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="password" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="LoginResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="loginResult" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="sid" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
</s:schema>
</wsdl:types>
<wsdl:message name="LoginSoapIn">
<wsdl:part name="parameters" element="tns:Login" />
</wsdl:message>
<wsdl:message name="LoginResponseSoapOut">
<wsdl:part name="parameters" element="tns:LoginResponse" />
</wsdl:message>
<wsdl:portType name="TestServiceSoap">
<wsdl:operation name="Login">
<wsdl:input message="tns:LoginSoapIn" />
<wsdl:output message="tns:LoginResponseSoapOut" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TestServiceSoap" type="tns:TestServiceSoap">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="Login">
<soap:operation soapAction="http://test/ExampleWs.php?Login" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="testService">
<wsdl:port name="testServiceSoap" binding="tns:testServiceSoap">
<soap:address location="http://test/ExampleWs.php?" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
和我希望在此Call
上使用Webservice
登录功能的方法:
public void LoginToWsdl(){
final String SOAP_ACTION = "http://test/ExampleWs.php?Login";
final String METHOD_NAME = "Login";
final String NAMESPACE = "http://test/ExampleWs.php";
final String URL = "http://test/wsdl/test.wsdl";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("login", "grzes");
request.addProperty("password", "grzes");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER12);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
try {
ht.call(SOAP_ACTION, envelope);
String response =envelope.getResponse().toString();
} catch (Exception e) {
e.printStackTrace();
}
}
问题是我一直得到org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope (position:START_TAG <{http://schemas.xmlsoap.org/wsdl/}wsdl:definitions targetNamespace='http://test/ExampleWs.php'>@10:99 in java.io.InputStreamReader@45ce5068)
当我使用SoapUI
测试我的网络服务时,一切正常。任何人都可以指出我在哪里做错了吗?