title: .NET WCF faults generating incorrect SOAP 1.1 faultcode values
body: <p>I am experimenting with using the FaultException and FaultException&lt;T&gt; to determine the best usage pattern in our applications. We need to support WCF as well as non-WCF service consumers/clients, including SOAP 1.1 and SOAP 1.2 clients.</p>
  
  <p>FYI: using FaultExceptions with wsHttpBinding results in SOAP 1.2 semantics whereas using FaultExceptions with basicHttpBinding results in SOAP 1.1 semantics. </p>
  
  <p>I am using the following code to throw a FaultException&lt;FaultDetails&gt;:</p>
  
  <pre><code>  throw new FaultException&lt;FaultDetails&gt;(
        new FaultDetails("Throwing FaultException&lt;FaultDetails&gt;."),
        new FaultReason("Testing fault exceptions."),
        FaultCode.CreateSenderFaultCode(new FaultCode("MySubFaultCode"))
        );
  </code></pre>
  
  <p>The FaultDetails class is just a simple test class that contains a string "Message" property as you can see below.</p>
  
  <p>When using wsHttpBinding the response is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-16"?&gt;
  &lt;Fault xmlns="http://www.w3.org/2003/05/soap-envelope"&gt;
  &lt;Code&gt;
    &lt;Value&gt;Sender&lt;/Value&gt;
    &lt;Subcode&gt;
      &lt;Value&gt;MySubFaultCode&lt;/Value&gt;
    &lt;/Subcode&gt;
  &lt;/Code&gt;
  &lt;Reason&gt;
    &lt;Text xml:lang="en-US"&gt;Testing fault exceptions.&lt;/Text&gt;
  &lt;/Reason&gt;
  &lt;Detail&gt;
    &lt;FaultDetails xmlns="http://schemas.datacontract.org/2004/07/ClassLibrary" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
      &lt;Message&gt;Throwing FaultException&amp;lt;FaultDetails&amp;gt;.&lt;/Message&gt;
    &lt;/FaultDetails&gt;
  &lt;/Detail&gt;
  </code></pre>
  
  <p></p>
  
  <p>This looks right according to the SOAP 1.2 specs. The main/root “Code” is “Sender”, which has a “Subcode” of “MySubFaultCode”. If the service consumer/client is using WCF the FaultException on the client side also mimics the same structure, with the faultException.Code.Name being “Sender” and faultException.Code.SubCode.Name being “MySubFaultCode”.</p>
  
  <p>When using basicHttpBinding the response is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-16"?&gt;
  &lt;s:Fault xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    &lt;faultcode&gt;s:MySubFaultCode&lt;/faultcode&gt;
    &lt;faultstring xml:lang="en-US"&gt;Testing fault exceptions.&lt;/faultstring&gt;
    &lt;detail&gt;
      &lt;FaultDetails xmlns="http://schemas.datacontract.org/2004/07/ClassLibrary" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
        &lt;Message&gt;Throwing FaultException&amp;lt;FaultDetails&amp;gt;.&lt;/Message&gt;
      &lt;/FaultDetails&gt;
    &lt;/detail&gt;
  &lt;/s:Fault&gt;
  </code></pre>
  
  <p>This does not look right. Looking at the SOAP 1.1 specs, I was expecting to see the “faultcode” to have a value of “s:Client.MySubFaultCode” when I use FaultCode.CreateSenderFaultCode(new FaultCode("MySubFaultCode")). Also a WCF client gets an incorrect structure. The faultException.Code.Name is “MySubFaultCode” instead of being “Sender”, and the faultException.Code.SubCode is null instead of faultException.Code.SubCode.Name being “MySubFaultCode”. Also, the faultException.Code.IsSenderFault is false.</p>
  
  <p>Similar problem when using FaultCode.CreateReceiverFaultCode(new FaultCode("MySubFaultCode")):</p>
  
  <ul>
  <li>works as expected for SOAP 1.2</li>
  <li>generates “s:MySubFaultCode” instead of “s:Server.MySubFaultCode” and the faultException.Code.IsReceiverFault is false for SOAP 1.1</li>
  </ul>
  
  <p>This item was also posted by someone else on <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=669420&amp;SiteID=1" rel="nofollow noreferrer">http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=669420&amp;SiteID=1</a> in 2006 and no one has answered it. I find it very hard to believe that no one has run into this, yet. </p>
  
  <p>Here is someone else having a similar problem: <a href="http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3883110&amp;SiteID=1&amp;mode=1" rel="nofollow noreferrer">http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=3883110&amp;SiteID=1&amp;mode=1</a></p>
  
  <p>Microsoft Connect bug: <a href="https://connect.microsoft.com/wcf/feedback/ViewFeedback.aspx?FeedbackID=367963" rel="nofollow noreferrer">https://connect.microsoft.com/wcf/feedback/ViewFeedback.aspx?FeedbackID=367963</a></p>
  
  <p>Description of how faults should work: <a href="http://blogs.msdn.com/drnick/archive/2006/12/19/creating-faults-part-3.aspx" rel="nofollow noreferrer">http://blogs.msdn.com/drnick/archive/2006/12/19/creating-faults-part-3.aspx</a></p>
  
  <p>Am I doing something wrong or is this truly a bug in WCF?</p>