Error Handling
As noted earlier, the Web architecture assumes failure. Web services inherit HTTP's design principle regarding failure, and attempt to improve on it. The SOAP specification has an entire section devoted to describing exactly how errors can be communicated. Of course, programmatic errors (either in the system or in the application) aren't the only kind of failures you can experience.
Definition: SOAP Header
A modular and composable piece of information that can be included in any SOAP message, similar to a footnote in a mail message, only more sophisticated. You can learn more about SOAP headers in Chapter 9.
For example, when you surf, you will often find that the page you are trying to access no longer exists. In other words, you'll see the Web master's dreaded 404 Not Found error. There is actually a large set of similar errors that HTTP presupposes may occur, such as pages moving either temporarily or permanently.
Web services inherit this idea of assuming failure and build on it. A significant section of the SOAP specification is about SOAP faults. A SOAP fault is a special message type used specifically for sending errors; Listing 1.2 shows an example. SOAP also specifies faults for an interesting set of failures. For example, SOAP defines the error you are supposed to send when you don't understand a SOAP header.
Listing 1.2: A SOAP Fault Message
HTTP/1.1 500 Internal Server Error Content-Type: text/xml; charset="utf-8" Content-Length: nnnn <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>SOAP-ENV:MustUnderstand</faultcode> <faultstring>Something bad happened.</faultstring> </SOAP-ENV:Fault> </SOAP-ENV:Body> </SOAP-ENV:Envelope>