What is the difference between a fault and exception in SOAP?
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
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/"> <env:Body> <env:Fault> <faultcode>env:Server</faultcode> <faultstring>Server Error</faultstring> <detail> <e:myfaultdetails xmlns:e="Some-URI"> <message> My application didn't work </message> <errorcode> 1001 </errorcode> </e:myfaultdetails> </detail> </env:Fault> </env:Body> </env:Envelope>
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"> <env:Header> <upg:Upgrade xmlns:upg="http://www.w3.org/2002/06/soap-upgrade"> <envelope qname="ns1:Envelope" xmlns:ns1="http://www.w3.org/2002/06/soap-envelope"/> <envelope qname="ns2:Envelope" xmlns:ns2="http://schemas.xmlsoap.org/soap/envelope/"/> </upg:Upgrade> </env:Header> <env:Body> <env:Fault> <env:Code><env:Value>env:VersionMismatch</env:Value></env:Code> <env:Reason>Version Mismatch</env:Reason> </env:Fault> </env:Body> </env:Envelope>
Notice that the element names within the <Fault> message are different. See the SOAP 1.2 spec for more details.
Dig Deeper on Simple Object Access Protocol (SOAP)
Related Q&A from Anne Thomas Manes
Anne Thomas Manes explains the differences between open source clients and open source implementations.continue reading
Anne Thomas Manes discusses the best way to go about creating an enterprise data dictionary and why the systems works well.continue reading
Anne Thomas Manes explains the difference between 'hard' real time and 'live' real time systems.continue reading
Have a question for an expert?
Please add a title for your question
Get answers from a TechTarget expert on whatever's puzzling you.