Creating Faults, Part 3

A fault code is an opaque string that classifies an error. The fault code string doesn't have to be meaningful, it could be "X", but having short yet meaningful strings can aid the debugging experience. The real meaning is in the fault reason that we talked about last time. In addition to the fault code string, there is an optional namespace for the fault code and the ability to nest another fault as a subcode. The fault subcode functions much like an inner exception.

We recognize three distinguished namespaces although you can supply any namespace string you'd like.

1.
The namespace for SOAP 1.1 defined faults is schemas.xmlsoap.org/soap/envelope/.
2.
The namespace for SOAP 1.2 defined faults is www.w3.org/2003/05/soap-envelope.
3.
We also have a special namespace for our POX-style unenveloped messages, which is schemas.microsoft.com/ws/2005/05/envelope/none.

The namespace string is also opaque rather than a real URI so you have to exactly match these strings to be recognized as a predefined namespace. There is no equivalence between two namespaces by operating on URI path components or anything like that.

 public class FaultCode
{
   public FaultCode(string name);
   public FaultCode(string name, FaultCode subCode);
   public FaultCode(string name, string ns);
   public FaultCode(string name, string ns, FaultCode subCode);

   public bool IsPredefinedFault { get; }
   public bool IsReceiverFault { get; }
   public bool IsSenderFault { get; }
   public string Name { get; }
   public string Namespace { get; }
   public FaultCode SubCode { get; }

   public static FaultCode CreateReceiverFaultCode(FaultCode subCode);
   public static FaultCode CreateReceiverFaultCode(string name, string ns);
   public static FaultCode CreateSenderFaultCode(FaultCode subCode);
   public static FaultCode CreateSenderFaultCode(string name, string ns);
}

There are a few well-known fault code strings defined in the SOAP specifications: VersionMismatch, MustUnderstand, Client/Sender, Server/Receiver, and DataEncodingUnknown (SOAP 1.2 only). The confusion over Client/Sender and Server/Receiver is the reason why there are all these special methods for receiver and sender faults. Client and Server are the SOAP 1.1 names while Sender and Receiver are the SOAP 1.2 names. We'll automatically pick the right version for you based on the namespace, with the default being the SOAP 1.2 names for namespaces we don't recognize (unenveloped messages also use the SOAP 1.2 names).

Next time: Tagging Glossary