2012-08-08 64 views
2

我想從Android(ICS)使用kso​​ap2訪問Web服務。 SOAP請求從我的Android模擬器發送是這樣的(這是給錯誤爲「soapenv:Server.generalException」 InvalidCredentialsFault):Soap請求格式爲android

<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> 
<LoginInput xmlns="http://xxxxxxx.com/Schemas/Core/2006-03/Session" id="o0" c:root="1"> 
<username i:type="d:string">uname</username> 
<password i:type="d:string">pass</password> 
<group i:type="d:string"></group> 
<role i:type="d:string"></role> 
</LoginInput> 
</v:Body> 
</v:Envelope> 

,而是形成了SoapUI,一個成功的登錄請求被髮送這樣的:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ses="http://xxxxxxx.com/Schemas/Core/2006-03/Session"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <ses:LoginInput username="uname" password="pass" group="" role=""/> 
    </soapenv:Body> 
</soapenv:Envelope> 

這裏是我的Android代碼段:

try {     
    final String NAMESPACE = "http://xxxxxxx.com/Schemas/Core/2006-03/Session"; 
    final String URL = "http://10.0.0.11:9081/toc/services/Core-2006-03-Session?wsdl"; 
    final String METHOD_NAME = "LoginInput"; 
    final String SOAP_ACTION = "login"; 

    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
    request.addProperty("username", "infodba"); 
    request.addProperty("password", "infodba"); 
    request.addProperty("group", ""); 
    request.addProperty("role", ""); 

    SoapSerializationEnvelope soapenvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    soapenvelope.setOutputSoapObject(request); 
    soapenvelope.dotNet = true; 

    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
    androidHttpTransport.debug = true; 

    try { 
     androidHttpTransport.call(SOAP_ACTION, soapenvelope); 
     Object response = (Object) soapenvelope.bodyIn; 
     tvResponse.setText(response.toString()); 
    } catch (Exception e) { 
     e.printStackTrace(); 
     tvResponse.setText("Exception Message:" + e.getMessage()); 
    } 
} catch (Exception e) { 
    e.printStackTrace(); 
    tvResponse.setText("Error: " + e.getClass().getName() + ":" + e.getMessage()); 
} 

我經歷了很多相關的線程上了計算器,並試圖這些選項,但未能獲得正確的登錄響應。

在一個嘗試了SoapUI我得到了同樣的錯誤響應,當我刪除一個屬性(用戶名=「UNAME」)的要求如下

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ses="http://xxxxxxx.com/Schemas/Core/2006-03/Session"> 
    <soapenv:Header/> 
    <soapenv:Body> 
     <ses:LoginInput password="pass" group="" role=""/> 
    </soapenv:Body> 
</soapenv:Envelope> 

我試圖kvmSerializable器具也不過同樣的錯誤(How to create SOAP request via ksoap2)。這裏是我的WSDL文件的一部分:XSD文件

<wsdl:definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:imp1="http://xxxxxxxx.com/Schemas/Soa/2006-03/Exceptions" xmlns:imp2="http://xxxxxxxx.com/Schemas/Core/2006-03/Session" xmlns:imp3="http://xxxxxxxx.com/webservices/2005-06/schemas/WSFaults" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://xxxxxxxx.com/Services/Core/2006-03" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsi="http://ws-i.org/schemas/conformanceClaim/" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xxxxxxxx.com/Services/Core/2006-03"> 
<wsdl:types> 
<xs:schema> 
<xs:import namespace="http://xxxxxxxx.com/Schemas/Soa/2006-03/Exceptions" schemaLocation="../schemas/SoaExceptions.xsd"/> 
<xs:import namespace="http://xxxxxxxx.com/Schemas/Core/2006-03/Session" schemaLocation="../schemas/Core0603Session.xsd"/> 
<xs:import namespace="http://xxxxxxxx.com/webservices/2005-06/schemas/WSFaults" schemaLocation="../schemas/WSFaults.xsd"/> 
</xs:schema> 
</wsdl:types> 

<wsdl:message name="loginRequest"> 
<wsdl:part element="imp2:LoginInput" name="in0"/> 
</wsdl:message> 
------- 
<wsdl:portType name="Core0603Session"> 
<wsdl:operation name="login"> 
<wsdl:input message="tns:loginRequest" name="loginRequest"/> 
<wsdl:output message="tns:loginResponse" name="loginResponse"/> 
<wsdl:fault message="tns:InternalServerFaultFault" name="InternalServerFaultError"/> 
<wsdl:fault message="tns:InvalidCredentialsFaultFault" name="InvalidCredentialsFaultError"/> 
</wsdl:operation> 
</wsdl:portType> 
------- 
<wsdl:binding name="Core0603SessionSoapBinding" type="tns:Core0603Session"> 
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 
<wsdl:operation name="login"> 
<soap:operation soapAction="login" style="document"/> 
<wsdl:input> 
<soap:body use="literal"/> 
</wsdl:input> 
<wsdl:output> 
<soap:body use="literal"/> 
</wsdl:output> 
<wsdl:fault name="InternalServerFaultError"> 
<soap:fault name="InternalServerFaultError" use="literal"/> 
</wsdl:fault> 
<wsdl:fault name="InvalidCredentialsFaultError"> 
<soap:fault name="InvalidCredentialsFaultError" use="literal"/> 
</wsdl:fault> 
</wsdl:operation> 
-------- 
</wsdl:binding> 
<wsdl:service name="Core0603SessionService"> 
<wsdl:port binding="tns:Core0603SessionSoapBinding" name="Core-2006-03-Session"> 
<soap:address location="http://10.0.0.11:9081/toc/services/Core-2006-03-Session"/> 
</wsdl:port> 
</wsdl:service> 
</wsdl:definitions> 

和部分:

<?xml version="1.0" encoding="UTF-8" ?> 
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    targetNamespace="http://xxxxxxxx.com/Schemas/Core/2006-03/Session" 
    xmlns:tns="http://xxxxxxxx.com/Schemas/Core/2006-03/Session" 
    elementFormDefault="qualified" attributeFormDefault="unqualified"> 
------ 
    <xsd:element name="LoginInput"> 
    <xsd:complexType> 
     <xsd:sequence> 
     </xsd:sequence> 
     <xsd:attribute name="username" type="xsd:string" use="required"> 
     </xsd:attribute> 
     <xsd:attribute name="password" type="xsd:string" use="required"> 
     </xsd:attribute> 
     <xsd:attribute name="group" type="xsd:string" use="required"> 
     </xsd:attribute> 
     <xsd:attribute name="role" type="xsd:string" use="required"> 
     </xsd:attribute> 
    </xsd:complexType> 
    </xsd:element> 
</xsd:schema> 

這裏是我responsedump:

<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><soapenv:Fault><faultcode>soapenv:Server.generalException</faultcode><faultstring/><detail><ns1:InvalidCredentialsFault xmlns:ns1="http://xxxxxxxx.com/Schemas/Soa/2006-03/Exceptions"><message code="1007" level="1007"/></ns1:InvalidCredentialsFault><ns2:exceptionName xmlns:ns2="http://xml.apache.org/axis/">com.xxxxxxxx.schemas.soa._2006_03.exceptions.InvalidCredentialsException</ns2:exceptionName><ns3:stackTrace xmlns:ns3="http://xml.apache.org/axis/"> 
    at com.xxxxxxxx.soa.ptier.ExceptionMapper.throwSoaException(Unknown Source) 
    at com.xxxxxxxx.soa.ptier.SoapInjector.sendRequestToPTier(Unknown Source) 
    at com.xxxxxxxx.services.core._2006_03.Core0603SessionSoapBindingImpl.login(Unknown Source) 
    at com.xxxxxxxx.services.core._2006_03.Core0603SessionSoapBindingSkeleton.login(Unknown Source) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:45) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37) 
    at java.lang.reflect.Method.invoke(Method.java:599) 
    at org.apache.axis.providers.java.RPCProvider.invokeMethod(RPCProvider.java:397) 
    at org.apache.axis.providers.java.RPCProvider.processMessage(RPCProvider.java:186) 
    at org.apache.axis.providers.java.JavaProvider.invoke(JavaProvider.java:323) 
    at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32) 
    at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118) 
    at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83) 
    at org.apache.axis.handlers.soap.SOAPService.invoke(SOAPService.java:454) 
    at org.apache.axis.server.AxisServer.invoke(AxisServer.java:281) 
    at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:699) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:738) 
    at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBase.java:327) 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:831) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1655) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1595) 
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:131) 
    at com.xxxxxxxx.presentation.gateway.filters.ResponseTimeFilter.doFilter(Unknown Source) 
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188) 
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116) 
    at com.xxxxxxxx.presentation.gateway.filters.CompressionFilter.doFilter(Unknown Source) 
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188) 
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116) 
    at com.xxxxxxxx.presentation.gateway.filters.ResponseTimeFilter.doFilter(Unknown Source) 
    at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:188) 
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:116) 
    at com.ibm.ws.webcontainer.filter.WebAppFilterChain._doFilter(WebAppFilterChain.java:77) 
    at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:908) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:932) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:500) 
    at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178) 
    at com.ibm.ws.webcontainer.servlet.CacheServletWrapper.handleRequest(CacheServletWrapper.java:91) 
    at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:864) 
    at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1583) 
    at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:186) 
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:455) 
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewInformation(HttpInboundLink.java:384) 
    at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:272) 
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214) 
    at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113) 
    at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165) 
    at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217) 
    at com.ibm.io.async.AsyncChannelFuture.fireCompletionActions(AsyncChannelFuture.java:161) 
    at com.ibm.io.async.AsyncFuture.completed(AsyncFuture.java:138) 
    at com.ibm.io.async.ResultHandler.complete(ResultHandler.java:204) 
    at com.ibm.io.async.ResultHandler.runEventProcessingLoop(ResultHandler.java:775) 
    at com.ibm.io.async.ResultHandler$2.run(ResultHandler.java:905) 
    at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1550) 
</ns3:stackTrace><ns4:hostname xmlns:ns4="http://xml.apache.org/axis/">xxxxxxx</ns4:hostname></detail></soapenv:Fault></soapenv:Body></soapenv:Envelope> 

原諒我這樣一個長期的代碼描述,但我希望這將有助於更好地理解問題和我的錯誤。總之,我希望獲得SoapUI請求格式的幫助,我知道它沒有強制性,但希望它能解決我的問題。如果可能,請給我任何其他備用。

+0

**答:** 一個長期的鬥爭,我發現的解決方案後,這是一個愚蠢的錯誤。在添加屬性的地方,我需要在我的SoapObject請求中添加屬性,如下所示: 'SoapObject request = new SoapObject(NAMESPACE,METHOD_NAME); request.addAttribute(「username」,「usrname」); request.addAttribute(「password」,「pass」); request.addAttribute(「group」,「」); request.addAttribute(「role」,「」); ' – VBond 2012-08-22 09:52:24

回答

0

嘗試使用的PropertyInfo

設置你的屬性
import org.ksoap2.serialization.PropertyInfo; 

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 

      PropertyInfo pi = new PropertyInfo(); 
      pi.setName("unamestring"); 
      pi.setValue("passwstring"); 
      pi.setType(String.class); 
      request.addProperty(pi); 
+0

感謝您的回覆,我已經嘗試過了,但它也給出了相同的回覆。 – VBond 2012-08-22 06:17:48

0
List<HeaderProperty> headerList = new ArrayList<HeaderProperty>(); 
     headerList.add(new HeaderProperty("Authorization", "Basic " 
       + org.kobjects.base64.Base64.encode("user:pass" 
         .getBytes()))); 

transporteHttp.call(SOAP_ACTION, sobre, headerList);