ksoap2 を使用して Android(ICS) から Web サービスにアクセスしようとしています。Androidエミュレーターから送信されるSOAPリクエストは次のようになります(「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 を 1 回試してみたところ、次のようにリクエストから 1 つの属性 (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 リクエスト形式を取得するための助けが必要です。強制ではないことはわかっていますが、問題が解決することを願っています。可能であれば、他の代替案を教えてください。