2010-05-24 75 views
1

我正嘗試在Android手機上使用kSOAP2訪問Webservice。我認爲連接正在建立,但服務器不會回答我的請求,因爲我沒有提供似乎在SOAP Version 1.1中需要的SOAP Action Header(如果我在這裏錯誤,請糾正我),我有使用,因爲服務器不支持版本1.2。 這是在請求中返回的具體Fault代碼看起來是這樣的:Android上的kSOAP2和SOAPAction

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

這是服務器(我運行它在本地主機)上生成的錯誤代碼如下所示:

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

,因爲我跑出來的想法.. 感謝鄉親任何意見將是巨大的!

回答

12

SOAP Action由名稱空間和您想要調用的實際方法組成。

另外,SOAP Action需要封裝在「」中才能工作。我有一個類似的錯誤,直到我用輔助方法來生成我的SOAP Action:

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

我希望它有幫助!

+0

沒有看到這個問題已近兩年了..我希望別人對此答案感到高興...... – htz 2012-05-10 07:32:45