Ashish
Ashish

Reputation: 1121

getting soap:Fault while consuming a soap service

I have a soap client which consumes a remote soap service. Everything is fine with the connection and setup. when I send a soap request, I get a soap fault message as following:

<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>

Now I am really having hard time understanding such error message. just for the fact, I know everything is fine with the request envelope. Could anyone please help me understand this error.

Here is the SOAP request Envelope:

  <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>

And here is the method signature which I am trying to invoke with the SOAP request.

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;

here is the part of 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>

Upvotes: 1

Views: 13787

Answers (1)

Christian Strempfer
Christian Strempfer

Reputation: 7383

Messages like Index: 0, Size: 0 are often caused by IndexOutOfBoundsExceptions.

In you're case that could mean:

  • The request is empty.
  • The request has the wrong encoding.
  • Security mechanisms won't let your request through.
  • There is an IndexOutOfBoundsException in the backend.

Next steps:

Check if your server accepts requests from SoapUI.

  • You have full control over the request, so if something goes wrong, it's probably an error in the backend.
  • If it works, there's a problem in your client. Check the request your client is sending. Is it complete? Does it contain unreadable characters?

Result: That error also occurs when using SoapUI.

XML / XML Schema

Some things in the XML and XML Schema attracted my attention.

  • In the request only createRequest uses a namespace. The other elements don't have a namespace, because they don't specify a namespace prefix. Using <createRequest xmlns="http://request.services.xyz.com/"> would assign a default namespace to all elements below createRequest.
  • (In XML Schema there is a reference to type="tns:dataFields" although there is only dataField. Also createRequest is lower case while in the request it's written with camel case. I assume both are not real problems, because you changed the names for StackOverflow.)

Server error

Since it's not possible to send any request the server accepts (not even with SoapUI), you definitly have to debug the server.

  • Is there any error message in the log?
  • Where does the Exception occur? Set a break point on java.lang.Exception and narrow it down until you find the problem.

Upvotes: 2

Related Questions