【发布时间】:2014-01-07 07:43:01
【问题描述】:
当我尝试使用kSOAP2 从Android 访问网络服务时,我收到了XmlPullParserException。
下面是我的代码:
NAMESPACE = "http://" + "10.99.60.52" + ":" + "8080" +"/ws/EmployeeServices?wsdl";
URL = "http://" + "10.99.60.52" + ":" + "8080" +"/ws/EmployeeServices";
SOAP_ACTION = "EmployeeServicesPortBinding";
METHOD_NAME = "authorize";
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("employeeId", userID);
request.addProperty("localeId", localeID);
request.addProperty("organizationId", organisationID);
request.addProperty("retailLocationId", retailLoationID);
request.addProperty("workstationId", workstationID);
request.addProperty("LoginInput", userID);
request.addProperty("Password", password);
request.addProperty("LoginInputType", loginInputType);
request.addProperty("Privilege", privilege);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try {
androidHttpTransport.call(SOAP_ACTION, envelope);
Object obj = envelope.bodyIn;
SoapObject response = null;
if (obj instanceof SoapObject)
response = (SoapObject) (envelope.bodyIn);
responseCode = (response != null) ? response.getProperty("UserAuthorizeResponse").toString() : "Failed";
Toast.makeText(getApplicationContext(), responseCode, Toast.LENGTH_SHORT).show(); //Testing
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "Exception", Toast.LENGTH_SHORT).show(); //Testing
System.out.println("");
}
WSDL:
<?xml version="1.0" encoding="UTF-8" ?>
- <!-- Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.7-b01-.
-->
- <!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.7-b01-.
-->
- <definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://ws.xx.com/xservices/EmployeeServices" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://ws.xx.com/xservices/EmployeeServices" name="EmployeeServices">
- <types>
- <xsd:schema>
<xsd:import namespace="http://ws.xx.com/xservices/EmployeeServices" schemaLocation="http://10.99.60.52:8080/ws/EmployeeServices?xsd=1" />
</xsd:schema>
</types>
- <message name="changePassword">
<part name="parameters" element="tns:changePassword" />
</message>
- <message name="changePasswordResponse">
<part name="parameters" element="tns:changePasswordResponse" />
</message>
- <message name="getCommissionedAssociates">
<part name="parameters" element="tns:getCommissionedAssociates" />
</message>
- <message name="getCommissionedAssociatesResponse">
<part name="parameters" element="tns:getCommissionedAssociatesResponse" />
</message>
- <message name="authorize">
<part name="parameters" element="tns:authorize" />
</message>
- <message name="authorizeResponse">
<part name="parameters" element="tns:authorizeResponse" />
</message>
- <message name="deleteMessage">
<part name="parameters" element="tns:deleteMessage" />
</message>
- <message name="deleteMessageResponse">
<part name="parameters" element="tns:deleteMessageResponse" />
</message>
- <message name="updateMessage">
<part name="parameters" element="tns:updateMessage" />
</message>
- <message name="updateMessageResponse">
<part name="parameters" element="tns:updateMessageResponse" />
</message>
- <message name="addMessage">
<part name="parameters" element="tns:addMessage" />
</message>
- <message name="addMessageResponse">
<part name="parameters" element="tns:addMessageResponse" />
</message>
- <message name="validateEmp">
<part name="parameters" element="tns:validateEmp" />
</message>
- <message name="validateEmpResponse">
<part name="parameters" element="tns:validateEmpResponse" />
</message>
- <message name="authenticate">
<part name="parameters" element="tns:authenticate" />
</message>
- <message name="authenticateResponse">
<part name="parameters" element="tns:authenticateResponse" />
</message>
- <portType name="EmployeeServices">
- <operation name="changePassword">
<input message="tns:changePassword" />
<output message="tns:changePasswordResponse" />
</operation>
- <operation name="getCommissionedAssociates">
<input message="tns:getCommissionedAssociates" />
<output message="tns:getCommissionedAssociatesResponse" />
</operation>
- <operation name="authorize">
<input message="tns:authorize" />
<output message="tns:authorizeResponse" />
</operation>
- <operation name="deleteMessage">
<input message="tns:deleteMessage" />
<output message="tns:deleteMessageResponse" />
</operation>
- <operation name="updateMessage">
<input message="tns:updateMessage" />
<output message="tns:updateMessageResponse" />
</operation>
- <operation name="addMessage">
<input message="tns:addMessage" />
<output message="tns:addMessageResponse" />
</operation>
- <operation name="validateEmp">
<input message="tns:validateEmp" />
<output message="tns:validateEmpResponse" />
</operation>
- <operation name="authenticate">
<input message="tns:authenticate" />
<output message="tns:authenticateResponse" />
</operation>
</portType>
- <binding name="EmployeeServicesPortBinding" type="tns:EmployeeServices">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
- <operation name="changePassword">
<soap:operation soapAction="" />
- <input>
<soap:body use="literal" />
</input>
- <output>
<soap:body use="literal" />
</output>
</operation>
- <operation name="getCommissionedAssociates">
<soap:operation soapAction="" />
- <input>
<soap:body use="literal" />
</input>
- <output>
<soap:body use="literal" />
</output>
</operation>
- <operation name="authorize">
<soap:operation soapAction="" />
- <input>
<soap:body use="literal" />
</input>
- <output>
<soap:body use="literal" />
</output>
</operation>
- <operation name="deleteMessage">
<soap:operation soapAction="" />
- <input>
<soap:body use="literal" />
</input>
- <output>
<soap:body use="literal" />
</output>
</operation>
- <operation name="updateMessage">
<soap:operation soapAction="" />
- <input>
<soap:body use="literal" />
</input>
- <output>
<soap:body use="literal" />
</output>
</operation>
- <operation name="addMessage">
<soap:operation soapAction="" />
- <input>
<soap:body use="literal" />
</input>
- <output>
<soap:body use="literal" />
</output>
</operation>
- <operation name="validateEmp">
<soap:operation soapAction="" />
- <input>
<soap:body use="literal" />
</input>
- <output>
<soap:body use="literal" />
</output>
</operation>
- <operation name="authenticate">
<soap:operation soapAction="" />
- <input>
<soap:body use="literal" />
</input>
- <output>
<soap:body use="literal" />
</output>
</operation>
</binding>
- <service name="EmployeeServices">
- <port name="EmployeeServicesPort" binding="tns:EmployeeServicesPortBinding">
<soap:address location="http://10.99.60.52:8080/ws/EmployeeServices" />
</port>
</service>
</definitions>
以下是我从 SOAP UI 发送的 SOAP 请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:emp="http://ws.xx.com/xservices/EmployeeServices">
<soapenv:Header/>
<soapenv:Body>
<emp:authorize>
<!--Optional:-->
<emp:ServiceContext>
<!--Optional:-->
<employeeId>8511</employeeId>
<!--Optional:-->
<localeId>en_US</localeId>
<!--Optional:-->
<organizationId>1</organizationId>
<!--Optional:-->
<retailLocationId>900</retailLocationId>
<!--Optional:-->
<workstationId>1</workstationId>
</emp:ServiceContext>
<!--Zero or more repetitions:-->
<LoginInput>8511</LoginInput>
<!--Optional:-->
<Password>1</Password>
<!--Optional:-->
<LoginInputType>KEYBOARD</LoginInputType>
<!--Optional:-->
<Privilege>SELL_ITEM</Privilege>
</emp:authorize>
</soapenv:Body>
</soapenv:Envelope>
这是我的 SOAP 响应,来自 SOAP UI:
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:authorizeResponse xmlns:ns2="http://ws.xx.com/xservices/EmployeeServices">
<UserAuthorizeResponse>
<userAuthorized>true</userAuthorized>
</UserAuthorizeResponse>
</ns2:authorizeResponse>
</S:Body>
</S:Envelope>
此行抛出异常:
androidHttpTransport.call(SOAP_ACTION, envelope);
更新错误:
expected: END_TAG {http://schemas.xmlsoap.org/soap/envelope/}Body (position:END_TAG </{http://schemas.xmlsoap.org/soap/envelope/}S:Fault>@1:314 in java.io.InputStreamReader@40ec86e0)
org.xmlpull.v1.XmlPullParserException: expected: END_TAG {http://schemas.xmlsoap.org/soap/envelope/}Body (position:END_TAG </{http://schemas.xmlsoap.org/soap/envelope/}S:Fault>@1:313 in java.io.InputStreamReader@3e89c3)
at org.kxml2.io.KXmlParser.exception(Unknown Source)
at org.kxml2.io.KXmlParser.require(Unknown Source)
at org.ksoap2.SoapEnvelope.parse(Unknown Source)
at org.ksoap2.transport.Transport.parseResponse(Unknown Source)
at org.ksoap2.transport.HttpTransportSE.call(Unknown Source)
at SOAPClass.main(SOAPClass.java:55)
谁能澄清我做错了什么?
【问题讨论】:
-
如果您可以将完整的堆栈跟踪添加到您的问题中,这将非常有帮助。
-
我没有任何其他信息。
-
你能在这里分享你的wsdl吗?
-
@user3090039:分享了我的 WSDL..
-
你能告诉我你是怎么抓到
SOAP response的吗?
标签: java android xml web-services soap