CN: 我正在使用 PHP 和 Android。我正在使用 nusoap 来制作 WSDL 服务器和 ksoap2 到客户端。尝试从 androidHttpTransport 执行方法调用时收到解析器错误
我在 PHP 中使用 WSDL 的 WSDL 代码并且执行没有错误。
错误:org.xmlpull.v1.XmlPullParserException:预期:START_TAG {http://schemas.xmlsoap.org/soap/envelope/}信封(位置:START_TAG @2:455 in java.io.InputStreamReader@4054fe80)
变量
private final static String WEB_SERVICE_URI = "http://172.224.116.242/test.php";
private final static String WEB_SERVICE_NAMESPACE = "urn:smspublish.aldeiati.com";
private final static String WS_METHOD_GET_TOKEN = "SBPublish.getToken";
Android 中的代码(ksoap2 - 客户端)
SoapObject parameters = new SoapObject(WEB_SERVICE_NAMESPACE,
WS_METHOD_GET_TOKEN);
parameters.addProperty("username", "test@aldeiati.com");
parameters.addProperty("password", "123456");
parameters.addProperty("deviceIMEI", "000000000000000");
parameters.addProperty("deviceDDI", "us");
parameters.addProperty("deviceNumber", "15555215554");
SoapSerializationEnvelope envelope = this.getEnvelope(parameters);
String host = this.getWebServiceURI();
HttpTransportSE androidHttpTransport = new HttpTransportSE(host);
androidHttpTransport
.setXmlVersionTag("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
androidHttpTransport.debug = true;
try {
androidHttpTransport.call(WS_METHOD_GET_TOKEN, envelope);
SoapObject response =(SoapObject) envelope.getResponse();
return response.toString();
} catch (IOException e) {
e.printStackTrace();
return null;
} catch (XmlPullParserException xe) {
xe.printStackTrace();
return null;
}
这是我的 WSDL
<?xml version="1.0" encoding="ISO-8859-1"?>
<definitions xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:smspublish.aldeiati.com" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="urn:smspublish.aldeiati.com">
<types>
<xsd:schema targetNamespace="urn:smspublish.aldeiati.com"
>
<xsd:import namespace="http://schemas.xmlsoap.org/soap/encoding/" />
<xsd:import namespace="http://schemas.xmlsoap.org/wsdl/" />
<xsd:complexType name="Token">
<xsd:all>
<xsd:element name="token" type="xsd:string"/>
<xsd:element name="expireIn" type="xsd:long"/>
<xsd:element name="status" type="xsd:int"/>
<xsd:element name="error" type="xsd:int"/>
</xsd:all>
</xsd:complexType>
</xsd:schema>
</types>
<message name="SBPublish.checkServerRequest">
<part name="nome" type="xsd:string" /></message>
<message name="SBPublish.checkServerResponse">
<part name="return" type="xsd:token" /></message>
<message name="SBPublish.syncServerRequest">
<part name="token" type="xsd:string" />
<part name="data" type="xsd:string" /></message>
<message name="SBPublish.syncServerResponse">
<part name="return" type="xsd:string" /></message>
<message name="SBPublish.getTokenRequest">
<part name="mail" type="xsd:string" />
<part name="password" type="xsd:string" />
<part name="deviceIMEI" type="xsd:string" />
<part name="deviceDDI" type="xsd:string" />
<part name="deviceNumber" type="xsd:string" /></message>
<message name="SBPublish.getTokenResponse">
<part name="return" type="tns:Token" /></message>
<portType name="smspublish.aldeiati.comPortType">
<operation name="SBPublish.checkServer">
<documentation>Testando o servidor</documentation>
<input message="tns:SBPublish.checkServerRequest"/>
<output message="tns:SBPublish.checkServerResponse"/>
</operation>
<operation name="SBPublish.syncServer">
<documentation>Transmite ao servidor o registro as atividades realizadas e recupera novas atividades</documentation>
<input message="tns:SBPublish.syncServerRequest"/>
<output message="tns:SBPublish.syncServerResponse"/>
</operation>
<operation name="SBPublish.getToken">
<documentation>Gera um token para comunicação entre o dispositivo e o servidor</documentation>
<input message="tns:SBPublish.getTokenRequest"/>
<output message="tns:SBPublish.getTokenResponse"/>
</operation>
</portType>
<binding name="smspublish.aldeiati.comBinding" type="tns:smspublish.aldeiati.comPortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="SBPublish.checkServer">
<soap:operation soapAction="SBPublish.checkServer" style="rpc"/>
<input><soap:body use="encoded" namespace="urn:smspublish.aldeiati.com" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
<output><soap:body use="encoded" namespace="urn:smspublish.aldeiati.com" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>
</operation>
<operation name="SBPublish.syncServer">
<soap:operation soapAction="SBPublish.syncServer" style="rpc"/>
<input><soap:body use="encoded" namespace="urn:smspublish.aldeiati.com" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
<output><soap:body use="encoded" namespace="urn:smspublish.aldeiati.com" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>
</operation>
<operation name="SBPublish.getToken">
<soap:operation soapAction="SBPublish.getToken" style="rpc"/>
<input><soap:body use="encoded" namespace="urn:smspublish.aldeiati.com" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></input>
<output><soap:body use="encoded" namespace="urn:smspublish.aldeiati.com" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/></output>
</operation>
</binding>
<service name="smspublish.aldeiati.com">
<port name="smspublish.aldeiati.comPort" binding="tns:smspublish.aldeiati.comBinding">
<soap:address location="http://172.224.116.242/test.php"/>
</port>
</service>
</definitions>
这就是我的 android 做的
<?xml version="1.0" encoding="UTF-8"?>
<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://schemas.xmlsoap.org/soap/envelope/">
<v:Header />
<v:Body>
<n0:SBPublish.getToken id="o0" c:root="1" xmlns:n0="urn:smspublish.aldeiati.com">
<username i:type="d:string">test@aldeiati.com</username>
<password i:type="d:string">123456</password>
<deviceIMEI i:type="d:string">000000000000000</deviceIMEI>
<deviceDDI i:type="d:string">us</deviceDDI>
<deviceNumber i:type="d:string">15555215554</deviceNumber>
</n0:SBPublish.getToken>
</v:Body>
</v:Envelope>
这是使用 android 制作的 xml 在soapUI 中收到的响应
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="urn:smspublish.aldeiati.com">
<SOAP-ENV:Body>
<ns1:SBPublish.getTokenResponse xmlns:ns1="urn:smspublish.aldeiati.com">
<return xsi:type="tns:Token">
<token xsi:type="xsd:string">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</token>
<expireIn xsi:type="xsd:long">180000</expireIn>
<status xsi:type="xsd:int">authorized</status>
<error xsi:type="xsd:int">200</error>
</return>
</ns1:SBPublish.getTokenResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
我在soapUI中使用这个xml来测试web服务,Android创建的xml是正确的。
在android中调用执行时会出现异常:
httpTransportSE.call(WS_METHOD_POLL_SERVER, envelope);