我正在尝试使用 ksoap2 从 Android(ICS) 访问 Web 服务。从我的 android 模拟器发送的肥皂请求是这样的(它给出的错误是 'soapenv:Server.generalException' InvalidCredentialsFault):
<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());
}
我在stackoverflow上浏览了许多相关线程并尝试了这些选项,但未能获得正确的登录响应。
在 SoapUI 的一次尝试中,当我从请求中删除一个属性 (username="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实现但同样的错误(如何通过 ksoap2 创建 SOAP 请求)。这是我的WSDL文件的一部分:
<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>
和xsd文件的一部分:
<?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>
这是我的响应转储:
<?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 请求的 Soap 请求格式,我知道它不是强制的,但希望它能解决我的问题。如果可能,请给我任何其他替代品。