WSDL - Fault element in WSDL

What is the Fault Element?

The <fault> element in WSDL defines the error messages that a web service operation can return if something goes wrong.
It allows exceptions to be described in a structured, machine-readable way, so clients know what types of errors to expect and how to handle them.


Where is Fault Used?

  • The <fault> element is defined inside an operation of a portType.

  • It is linked to a message element (like input and output).

  • The same fault definition is then extended inside the binding section (e.g., SOAP fault).


Structure of a Fault Element

<operation name="GetWeather">
  <input message="tns:GetWeatherRequest"/>
  <output message="tns:GetWeatherResponse"/>
  <fault name="InvalidCityFault" message="tns:InvalidCityMessage"/>
</operation>
  • name – Name of the fault (e.g., InvalidCityFault).

  • message – Refers to a <message> element that describes the structure of the error.


Example with SOAP Fault Binding

<binding name="WeatherBinding" type="tns:WeatherPortType">
  <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
  <operation name="GetWeather">
    <soap:operation soapAction="http://example.com/GetWeather"/>
    <input><soap:body use="literal"/></input>
    <output><soap:body use="literal"/></output>
    <fault name="InvalidCityFault">
      <soap:fault name="InvalidCityFault" use="literal"/>
    </fault>
  </operation>
</binding>

Here:

  • The portType operation defines the abstract fault.

  • The binding section maps it to a SOAP fault message (how the fault is sent over the wire).


Why Fault Element is Useful?

  1. Standardized Error Handling – Ensures clients know in advance what errors to expect.

  2. Structured Exceptions – Instead of raw text errors, faults are defined with XML schemas.

  3. Interoperability – Different systems can handle faults consistently across platforms.

  4. Better Client Applications – Developers can generate strongly-typed exceptions from WSDL.


In short:

  • Input = Request message

  • Output = Response message

  • Fault = Error message (if something goes wrong)