EN:我正在使用PHP和Android。我正在使用nusoap创建一个WSDL服务器和ksoap2到客户端。尝试从androidHttpTransport
执行方法调用时,我收到解析器错误我在PHP中使用WSDL WSDL代码,并且无错误地执行。
错误: org.xmlpull.v1.XmlPullParserException:expected:START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope(位置:START_TAG @ 2:455,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 - client)
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>
这是使用xml make by android
在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中调用execute时发出异常:
httpTransportSE.call(WS_METHOD_POLL_SERVER, envelope);