SOAP - SOAP Fault

1. What is SOAP Fault?

  • A SOAP Fault is a special element inside the SOAP Body that is used to report errors.

  • If something goes wrong (client mistake, server issue, invalid message, etc.), the server does not return normal data; instead, it sends back a Fault message.

  • This provides a standard way of error handling in SOAP.


2. Location

  • Appears inside the <soap:Body> of a SOAP message.

  • Replaces the normal response when an error occurs.


3. Structure of SOAP Fault

A SOAP Fault message has these elements:

<soap:Fault>
   <faultcode>...</faultcode>
   <faultstring>...</faultstring>
   <faultactor>...</faultactor>
   <detail>...</detail>
</soap:Fault>

Elements:

  1. faultcode (mandatory)

    • Defines the type of error.

    • Common codes:

      • soap:Client → The request was invalid (e.g., wrong input).

      • soap:Server → The server failed to process a valid request.

      • soap:VersionMismatch → Wrong SOAP version used.

      • soap:MustUnderstand → A required header was not understood.

  2. faultstring (mandatory)

    • A human-readable description of the error (like an error message).

  3. faultactor (optional)

    • Indicates which node (server/intermediary) caused the error.

    • Useful in multi-hop SOAP messages (e.g., proxy servers).

  4. detail (optional)

    • Provides application-specific error details.

    • More technical information about what exactly went wrong.


4. Example of SOAP Fault

Case: Invalid City in Weather Request

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Client</faultcode>
         <faultstring>Invalid city name provided</faultstring>
         <faultactor>http://www.example.com/weatherService</faultactor>
         <detail>
            <errorcode>1001</errorcode>
            <errormessage>City 'Lnodon' not found in database</errormessage>
         </detail>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>
  • faultcodeClient (error caused by bad input).

  • faultstring → "Invalid city name provided".

  • faultactor → Service URL that raised the error.

  • detail → More information for debugging.


5. Key Points about SOAP Fault

  1. Fault is used for error handling in SOAP.

  2. Always appears inside the SOAP Body.

  3. Contains faultcode, faultstring, faultactor, detail.

  4. Provides both human-readable and technical details about the error.

  5. Ensures that SOAP clients can handle errors in a consistent, standard way.