For the previous article (WCF basic exception handling mode: [Previous], [Medium], [next article]), mainly in the perspective of the end developer of the WCF on the exception handling programming model introduced, next, we need to move our eyes to the WCF framework, in-depth analysis of the entire WCF exception handling process. In the SOAP-based message exchange process, the exception is ultimately hosted by the fault message, so it is natural that the next introduction starts with the SOAP fault.
I. Speaking from the SOAP Fault (SOAP 1.2 based)
The final implementation of the service invocation is accomplished through a message exchange, and WCF can be viewed as a framework for message processing in nature. Message, not only carries the request and reply of the normal service invocation, the message is still the carrier of the error message when the exception occurs. This year, though, with the rapid development of rest, the pox (Plain of XML) message exchange is on the line, Ajax continues to warm up, but also based on non-XML (JSON) message began to hot, but it is undeniable that in the future for a short period of time soap remains the mainstream. To see how many ws-* specifications or standards are based on soap, there should be no doubt about this assertion.
The consortium has issued two specifications on soap: SOAP 1.1 and SOAP 1.2. In the 5th chapter of WCF Profiling (Volume 1), I have covered soap in a comprehensive way, including soap Fault, in the SOAP 1.2 specification. Because exceptions are hosted by fault messages in a message exchange, many of the necessary specifications for the SOAP fault need to be repeated, and the other related content of soap is no longer described here.
To understand the specification of SOAP 1.2 for SOAP fault under SOAP 1.2, let's first look at a fault soap with a complete structure.
1: <s:envelope xmlns:a= "http://www.w3.org/2005/08/addressing" xmlns:s= "Http://www.w3.org/2003/05/soap-envelope" ">
2: <s:Header>
3: <a:action s:mustunderstand= "1" >http://www.artech.com/icalculator/dividecalculationerrorfault</a: Action>
4: </s:Header>
5: <s:Body>
6: <s:Fault>
7: <s:Code>
8: <s:Value>s:Sender</s:Value>
9: <s:Subcode>
<s:value xmlns:a= "http://www.artech.com/" >a:CalculationError</s:Value>
One: </s:Subcode>
</s:Code>
<s:Reason>
<s:text xml:lang= "ZH-CN" > Dividend y cannot be zero!</s:text>
: </s:Reason>
: <s:Node>http://http://www.artech.com/calculationcenter</s:Node>
: <s:Role>http://http://www.artech.com/calculatorservice</s:Role>
: <s:Detail>
: <calculationerror xmlns:i= "http://www.w3.org/2001/XMLSchema-instance" xmlns= "http://www.artech.com/" >
<Message> Dividend y cannot be zero!</message>
<Operation>Divide</Operation>
</CalculationError>
: </s:Detail>
: </s:Fault>
: </s:Body>
: </s:Envelope>
The above soap is a very complete fault message, its body part contains the elements that make up all types of SOAP fault (required and optional), and then we'll introduce the SOAP 1.2 specification to soap on the basis of this fault message The relevant provisions of fault.
In the SOAP 1.2 specification, SOAP fault is used as the body of a fault SOAP message to host error-related information. Specifically, there are several specifications for the SOAP fault element:
The element name must be fault;
The element namespace must be http://www.w3.org/2003/05/soap-envelope;
The element contains the following child elements (the values in parentheses that represent each of the child elements in the fault soap given above):
1, a necessary code element to represent error codes;
2, one such as the reason element to indicate the cause of the error;
3, an optional node element represents the SOAP node that caused the error (SOAP nodes);
4. An optional role element represents the corresponding roles of the SOAP node;
5. An optional detail describes a detailed description of the error.
Next, we make a simple introduction to the five child elements that make up the SOAP fault.
1. Fault code element
The code element of the SOAP fault, which is an error code that can be broadly regarded as a classification of errors. SOAP 1.2 makes the following specifications for the format of the code element:
The element name must be "Code" and the namespace name is "Http://www.w3.org/2003/05/soap-envelope";
The code element can only contain child elements of the following two types;
1, a necessary value element to define the error code;
2, an optional subcode element is used to define the error child code.
For the format of the value element, it has the following specifications:
The element name must be "Value" and the namespace name is "Http://www.w3.org/2003/05/soap-envelope";
The element type is the "Env:faultcodeenum" enumeration, and the table below lists all the optional enumeration values.
enumeration value |
Meaning |
VersionMismatch |
namespace or name and specified SOAP specification do not match |
MustUnderstand |
The target SOAP node does not understand and processes the SOAP header with the MustUnderstand property of "true" or "1" |
Dataencodingunknown |
The data encoding of the SOAP header or principal is not supported by the target SOAP node |
Sender |
The message format is legitimate or lacks the necessary data |
Receiver |
SOAP node Processing message error |