Problem solve Get help with specific problems with your technologies, process and projects.

What is the difference between a fault and an exception in SOAP?

What is the difference between a fault and exception in SOAP?

There is no such thing as an exception in SOAP. There are only faults. A fault is a response message to a request message that could not be processed. The <FAULT> response message is the only SOAP body structure that has been defined. In SOAP 1.1, a <FAULT> message should look something like this:

  <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
           <faultstring>Server Error</faultstring>
               <e:myfaultdetails xmlns:e="Some-URI">
                   My application didn't work

There are four possible <faultcode> values: VersionMismatch, MustUnderstand, Client, and Server, indicating, respectively: the SOAP service didn't understand your SOAP envelope; the SOAP service didn't understand a SOAP Header that specified mustUnderstand=1; the client sent an invalid message (or invalid data within the message); and the server was unable to process the message due to some error it encountered. You may extend these basic codes with subcodes, e.g., Client.InvalidArgument. The <detail> element can contain whatever detailed information you want to send back, such as a Java exception. Depending on the SOAP implementation you use, the client SOAP runtime system may be able to rethrow the Java exception.

The SOAP 1.2 <FAULT> element is a bit different. Here's an example of a VersionMismatch fault:

 <env:Envelope xmlns:env="http://www.w3.org/2002/06/soap-envelope">
   <upg:Upgrade xmlns:upg="http://www.w3.org/2002/06/soap-upgrade">
    <envelope qname="ns1:Envelope"
    <envelope qname="ns2:Envelope"
     <env:Reason>Version Mismatch</env:Reason>

Notice that the element names within the <Fault> message are different. See the SOAP 1.2 spec for more details.

This was last published in September 2002

Dig Deeper on Service-oriented architecture (SOA)



Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.