Android上的kSOAP2和SOAPAction

时间:2010-05-24 18:45:56

标签: android action ksoap2

我正在尝试在Android手机上使用kSOAP2访问Web服务。我认为连接正在建立,但服务器将不会回答我的请求,因为我没有提供SOAP操作头,这似乎是SOAP版本1.1中所需要的(如果我错了请纠正我)我有使用,因为服务器不支持1.2版。 在请求中返回的具体Faultcode如下所示:

faultactor  null    
faultcode   "S:Server" (id=830064966432)    
faultstring "String index out of range: -11" (id=830064966736)

在服务器上生成的错误代码(我在localhost上运行它)如下所示:

4.05.2010 20:20:29 com.sun.xml.internal.ws.transport.http.HttpAdapter fixQuotesAroundSoapAction
WARNUNG: Received WS-I BP non-conformant Unquoted SoapAction HTTP header: http://server.contextlayer.bscwi.de/createContext
24.05.2010 20:20:29 com.sun.xml.internal.ws.server.sei.EndpointMethodHandler invoke
SCHWERWIEGEND: String index out of range: -11
java.lang.StringIndexOutOfBoundsException: String index out of range: -11
    at java.lang.String.substring(Unknown Source)
    at de.bscwi.contextlayer.xml.XmlValidator.isValid(XmlValidator.java:41)
    at de.bscwi.contextlayer.server.ContextWS.createContext(ContextWS.java:45)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.xml.internal.ws.api.server.InstanceResolver$1.invoke(Unknown Source)
    at com.sun.xml.internal.ws.server.InvokerTube$2.invoke(Unknown Source)
    at com.sun.xml.internal.ws.server.sei.EndpointMethodHandler.invoke(Unknown Source)
    at com.sun.xml.internal.ws.server.sei.SEIInvokerTube.processRequest(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Unknown Source)
    at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Unknown Source)
    at com.sun.xml.internal.ws.server.WSEndpointImpl$2.process(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.HttpAdapter$HttpToolkit.handle(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.HttpAdapter.handle(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handleExchange(Unknown Source)
    at com.sun.xml.internal.ws.transport.http.server.WSHttpHandler.handle(Unknown Source)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
    at sun.net.httpserver.AuthFilter.doFilter(Unknown Source)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
    at sun.net.httpserver.ServerImpl$Exchange$LinkHandler.handle(Unknown Source)
    at com.sun.net.httpserver.Filter$Chain.doFilter(Unknown Source)
    at sun.net.httpserver.ServerImpl$Exchange.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

WSDL的相关部分(至少我正在考虑的那部分)看起来像这样:

<operation name="createContext">
<soap:operation soapAction=""/>
−
<input>
<soap:body use="literal" namespace="http://server.contextlayer.bscwi.de/"/>
</input>
−
<output>
<soap:body use="literal" namespace="http://server.contextlayer.bscwi.de/"/>
</output>
</operation>    

在我的代码中我添加了一个Header,但似乎我做错了:

private static final String SOAP_ACTION  = "";
//...
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope (SoapEnvelope.VER11);
soapEnvelope.setOutputSoapObject(Request);
AndroidHttpTransport aht = new AndroidHttpTransport (URL);
//...
aht.call(SOAP_ACTION, soapEnvelope);
        SoapPrimitive resultString = (SoapPrimitive) soapEnvelope.getResponse();

任何建议都会很棒,因为我的想法已经用完了...... 谢谢大家!

1 个答案:

答案 0 :(得分:12)

SOAP Action由命名空间和要调用的实际方法组成。

此外,SOAP Action需要封装在“”中才能工作。我有一个类似的错误,直到我使用辅助方法生成我的SOAP Action:

public String getSoapAction(String method) {
    return "\"" + NAMESPACE + method + "\""; 
}

我希望它有所帮助!