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
  2. The namespace for SOAP 1.2 defined faults is
  3. We also have a special namespace for our POX-style unenveloped messages, which is

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

Comments (4)

  1. There is one fault that distinguishes itself from all the rest by the level of support built in for it

  2. The last piece of this eleven part series on fault messages covers advice for channel authors that need

  3. I haven’t forgotten about the goal to put together a table of contents for all of these articles. The