2013-12-10 82 views
1

我有一個使用遠程肥皂服務的肥皂客戶端。連接和設置一切正常。當我發送SOAP請求,我得到一個SOAP錯誤消息如下:獲得肥皂:消耗肥皂服務時發生故障

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
<soap:Body> 
    <soap:Fault> 
    <faultcode>soap:Server</faultcode> 
    <faultstring>Index: 0, Size: 0</faultstring> 
    </soap:Fault> 
</soap:Body> 
</soap:Envelope> 

現在我真的有很難理解這樣的錯誤消息。只是爲了這個事實,我知道請求信封一切正常。任何人都可以請幫我理解這個錯誤。

這裏是SOAP請求信封:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <ns2:createRequest xmlns:ns2="http://request.services.xyz.com/"> 
    <hid>1234</hid> 
    <requestTypeCode>APPOINT_REQ</requestTypeCode> 
    <createdBy>testuser</createdBy> 
    <assignedTo>testuser</assignedTo> 
    <data> 
    <dataField> 
    <name>ContentText</name> 
    <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">Test!</value> 
    </dataField> 
    <dataField> 
    <name>Date</name> 
    <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:dateTime">2013-12-09T13:28:34.009-05:00</value> 
    </dataField> 
    <dataField> 
    <name>OrderNumber</name> 
    <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:string">1-123432</value> 
    </dataField> 
    </data> 
    <originAppCode>ABCD</originAppCode> 
</ns2:createRequest> 
</soap:Body> 
</soap:Envelope> 

這裏是我試圖用SOAP請求調用的方法簽名。

public @XmlElement(name="Request")Request createRequest(@WebParam(name="hid")int hid, @WebParam(name="requestTypeCode")String requestTypeCode, @WebParam(name="createdBy")String createdBy, 
     @WebParam(name="assignedTo")String assignedTo, @WebParam(name="createTime")Date createTime, @WebParam(name="data")DataFields data, @WebParam(name="originAppCode") String originAppCode) throws Exception; 

這裏是WSDL的一部分:

<wsdl:definitions xmlns:ns1="http://cxf.apache.org/bindings/xformat" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://request.services.xyz.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="requestServiceImplService" targetNamespace="http://request.services.xyz.com/"> 
<wsdl:types> 
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://jaxb.dev.java.net/array" version="1.0"> 
    <xs:complexType final="#all" name="stringArray"> 
    <xs:sequence> 
     <xs:element maxOccurs="unbounded" minOccurs="0" name="item" nillable="true" type="xs:string"/> 
    </xs:sequence> 
    </xs:complexType> 
    </xs:schema> 
    <xs:schema xmlns:tns="http://request.services.xyz.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" targetNamespace="http://request.services.xyz.com/" version="1.0"> 
    <xs:element name="createRequest" type="tns:createRequest"/> 
    <xs:element name="createRequestResponse" type="tns:createRequestResponse"/> 
    <xs:element name="dataFields" type="tns:dataFields"/> 
    <xs:complexType name="createRequest"> 
    <xs:sequence> 
    <xs:element name="hid" type="xs:int"/> 
    <xs:element minOccurs="0" name="requestTypeCode" type="xs:string"/> 
    <xs:element minOccurs="0" name="createdBy" type="xs:string"/> 
    <xs:element minOccurs="0" name="assignedTo" type="xs:string"/> 
    <xs:element minOccurs="0" name="createTime" type="xs:dateTime"/> 
    <xs:element minOccurs="0" name="data" type="tns:dataFields"/> 
    <xs:element minOccurs="0" name="originAppCode" type="xs:string"/> 
    </xs:sequence> 
    </xs:complexType> 
    <xs:complexType name="createRequestResponse"> 
    <xs:sequence> 
    <xs:element minOccurs="0" name="return" type="tns:request"/> 
    </xs:sequence> 
    </xs:complexType> 
    <xs:complexType name="dataFields"> 
    <xs:sequence> 
    <xs:element maxOccurs="unbounded" minOccurs="0" name="dataField" type="tns:dataField"/> 
    </xs:sequence> 
    </xs:complexType> 
    <xs:complexType name="dataField"> 
    <xs:sequence> 
    <xs:element name="name" type="xs:string"/> 
    <xs:element name="value" type="xs:anyType"/> 
    </xs:sequence> 
    </xs:complexType> 
    </xs:schema> 
</wsdl:types> 
<wsdl:message name="createRequest"> 
    <wsdl:part element="tns:createRequest" name="parameters"></wsdl:part> 
</wsdl:message> 
<wsdl:message name="createRequestResponse"> 
    <wsdl:part element="tns:createRequestResponse" name="parameters"></wsdl:part> 
</wsdl:message> 
<wsdl:operation name="createRequest"> 
    <wsdl:input message="tns:createRequest" name="createRequest"></wsdl:input> 
    <wsdl:output message="tns:createRequestResponse" name="createRequestResponse"> </wsdl:output> 
</wsdl:operation> 
<wsdl:binding name="RequestServiceImplServiceSoapBinding" type="tns:IRequestService"> 
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> 
<wsdl:operation name="createRequest"> 
    <soap:operation soapAction="" style="document"/> 
    <wsdl:input name="createRequest"> 
    <soap:body use="literal"/> 
    </wsdl:input> 
    <wsdl:output name="createRequestResponse"> 
    <soap:body use="literal"/> 
    </wsdl:output> 
    </wsdl:operation> 
</wsdl:binding> 
<wsdl:service name="RequestServiceImplService"> 
<wsdl:port binding="tns:RequestServiceImplServiceSoapBinding" name="RequestServiceImplPort"> 
    <soap:address location="location_where_service_is_being_hosted/cxf/jaxws/RequestService"/> 
</wsdl:port> 
</wsdl:service> 
</wsdl:definitions> 
+0

您能否粘貼您要發送的請求 –

+0

我剛剛編輯了問題並將其添加到上面。對不起,以前沒有添加它。 – Ashish

+0

@Ashish,你還可以檢查你在服務器端獲得的所有例外情況。 –

回答

2

消息像Index: 0, Size: 0常常是由於IndexOutOfBoundsException秒。

在你這可能意味着情況:

  • 的要求是空的。
  • 該請求具有錯誤的編碼。
  • 安全機制不會讓你的請求通過。
  • 後臺有一個IndexOutOfBoundsException

下一個步驟:如果您的服務器接受來自SoapUI請求

檢查。

  • 您可以完全控制請求,所以如果出現問題,可能是後端錯誤。
  • 如果有效,客戶端存在問題。檢查你的客戶發送的請求。它是否完整?它是否包含無法讀取的字符?

結果:使用了SoapUI時也會發生錯誤。

XML/XML模式

在XML有些東西和XML Schema吸引了我的注意。

  • 僅在請求createRequest使用命名空間。其他元素沒有名稱空間,因爲它們沒有指定名稱空間前綴。使用<createRequest xmlns="http://request.services.xyz.com/">會爲createRequest以下的所有元素分配默認名稱空間。
  • (在XML Schema中有對type="tns:dataFields"的引用,儘管只有dataField。另外createRequest是小寫,而在請求中它是用駱駝事件寫的。我認爲這兩種都不是真正的問題,因爲你改變了名字的StackOverflow。)

Server錯誤

因爲它是不可能通過發送服務器接受的請求(即使不是了SoapUI),你明確地必須調試服務器。

  • 日誌中是否有任何錯誤消息?
  • 異常發生在哪裏?在java.lang.Exception上設置一個斷點並縮小直到找到問題。
+0

做soap:服務器意味着錯誤來自服務器端。只是爲了說明,該服務在其後端訪問數據庫。我嘗試了與SoapUI相同的請求信封,但我得到了同樣的錯誤。 – Ashish

+0

我很抱歉混淆,那些是我的錯誤。我剛剛編輯了wsdl,以免讓人感到困惑。我查看了服務器日誌。我發現有同樣的錯誤「IndexOutOfBoundException」。謝謝 – Ashish

+0

嗨,我能弄清楚這個問題。我在SOAP請求中發送的「requestTypeCode」的值在數據庫中不存在,並且由於該typeCode無法映射到Database表中的任何值,因此它發送了IndexOutOfBound異常。非常感謝您幫助我調試問題。 – Ashish