1

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

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>    

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

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();

任何建议都会很棒,因为我的想法已经不多了。谢谢大家!

4

1 回答 1

13

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

此外,需要将 SOAP Action 封装在“”中才能工作。在我使用辅助方法生成 SOAP 操作之前,我遇到了类似的错误:

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

我希望它有帮助!

于 2012-05-10T07:31:45.680 回答