首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >异常- kSOAP2

异常- kSOAP2
EN

Stack Overflow用户
提问于 2014-01-07 07:43:01
回答 2查看 2.9K关注 0票数 1

当我尝试使用XmlPullParserExceptionAndroid访问web服务时,我得到了kSOAP2

下面是我的代码:

代码语言:javascript
复制
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:

代码语言:javascript
复制
<?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:发送的SOAP请求

代码语言:javascript
复制
<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:

代码语言:javascript
复制
<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>

--这一行抛出在异常之下:

代码语言:javascript
复制
androidHttpTransport.call(SOAP_ACTION, envelope);

更新错误:

代码语言:javascript
复制
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)

有人能澄清我做错了什么吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-01-09 06:14:27

终于解决了。

由于无效的kSOAP.jar。

我们需要升级到2.5.8。以前,我一直在使用2.5.4。

参考:http://code.google.com/p/ksoap2-android/issues/detail?id=7

JAR链接:http://www.java2s.com/Code/Jar/k/Downloadksoap2androidassembly258jarwithdependenciesjar.htm

票数 4
EN

Stack Overflow用户

发布于 2014-01-07 08:15:25

根据您的wsdl,您需要更改您的代码。

代码语言:javascript
复制
  NAMESPACE = "http://ws.xx.com/xservices/EmployeeServices/";
  URL= "http://10.99.60.52:8080/ws/EmployeeServices";
  SOAP_ACTION ="";

让我知道,你现在得到了什么,如果你需要进一步解释这些。

更新:

代码语言:javascript
复制
NAMESPACE = "http://" + "10.99.60.52" + ":" + "8080" +"/ws/EmployeeServices?wsdl";

上面是您的wsdl URL而不是名称空间,它可以用作url。

代码语言:javascript
复制
URL = "http://" + "10.99.60.52" + ":" + "8080" +"/ws/EmployeeServices"; 

这是正确的。发布where服务的正是您的端点url。

代码语言:javascript
复制
SOAP_ACTION = "EmployeeServicesPortBinding";

这是绑定名称,而不是soap操作。你的肥皂动作是空白的。你可以在装订下看到。

代码语言:javascript
复制
<soap:operation soapAction="" /> 

如果空白soap操作不起作用,请尝试将SOAP_ACTION设置为"namspace/soapAction“。

代码语言:javascript
复制
SOAP_ACTION="http://ws.xx.com/xservices/EmployeeServices/";

如果您有任何混淆,请参考这些在线教程。

kSOAP2 android教程:

代码语言:javascript
复制
http://javatutorialspoint.blogspot.com/2012/02/android-web-service-access-using-ksoap2.html
http://seesharpgears.blogspot.de/2010/11/basic-ksoap-android-tutorial.html
http://stackoverflow.com/questions/11037852/how-to-recieve-a-message-from-a-webservice-with-ksoap2-and-android
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20966426

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档