title: BizTalk Orchestration: Respond with Untyped SOAP Fault
body: <p>I have a BizTalk 2009 orchestration with a request-response port type that is published as a WCF Basic-HTTP web service.  The port has one operation, and that operation has request and response messages with appropriate schemas.  After receiving a request on this port, there are a few cases where a fault message should be returned to the client instead of the standard response message.  I'm having difficulty getting the correct fault message back to the client.  I'd like to be able to set both the <code>faultcode</code> and <code>faultstring</code> elements of the SOAP fault message.  Here's what I've tried:</p>
  
  <p><strong>Adding a Fault Message of Type String</strong>:
  I tried adding a fault message with a message type of string to the operation.  Within the orchestration, I constructed a string message and sent it as the response.  The fault that was delivered back to the client looked like:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"&gt;
     &lt;s:Body&gt;
        &lt;s:Fault&gt;
           &lt;faultcode xmlns:a="http://schemas.microsoft.com/net/2005/12/windowscommunicationfoundation/dispatcher"&gt;a:InternalServiceFault&lt;/faultcode&gt;
           &lt;faultstring xml:lang="en-US"&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&gt;
  &amp;lt;string&gt;This is the error message.&amp;lt;/string&gt;&lt;/faultstring&gt;
           &lt;detail&gt;
              &lt;ExceptionDetail xmlns="http://schemas.datacontract.org/2004/07/System.ServiceModel" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"&gt;
                 &lt;HelpLink i:nil="true"/&gt;
                 &lt;InnerException i:nil="true"/&gt;
                 &lt;Message&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&gt;
  &amp;lt;string&gt;This is the error message.&amp;lt;/string&gt;&lt;/Message&gt;
                 &lt;StackTrace&gt;at Microsoft.BizTalk.Adapter.Wcf.Runtime.BizTalkAsyncResult.End() ...&lt;/StackTrace&gt;
                 &lt;Type&gt;Microsoft.BizTalk.Adapter.Wcf.Runtime.BizTalkNackException&lt;/Type&gt;
              &lt;/ExceptionDetail&gt;
           &lt;/detail&gt;
        &lt;/s:Fault&gt;
     &lt;/s:Body&gt;
  &lt;/s:Envelope&gt;
  </code></pre>
  
  <p>This almost works, except the <code>faultstring</code> element contains the xml serialized version of my string instead of the string itself.  I also cannot set the <code>faultcode</code> element.</p>
  
  <p><strong>Adding a Fault Message of Type <code>http://schemas.xmlsoap.org/soap/envelope/#Fault</code></strong>
  I thought I might be able to convince BizTalk to return a fault message along the lines of what I'd expect if I constructed the <code>Fault</code> element and sent that.  So I added a fault message with a type of <code>http://schemas.xmlsoap.org/soap/envelope/#Fault</code>, constructed the appropriate message and sent that as the response.  The result was the same as above, except instead of a string, the <code>faultstring</code> element contained a <code>CDATA</code> section with the entire xml message I had constructed inside.</p>
  
  <p>So I'm stuck now; I feel like this should be a simple task in BizTalk.  The documentation on MSDN, <a href="http://msdn.microsoft.com/en-us/library/bb226394%28BTS.70%29.aspx" rel="nofollow">How to Throw Fault Exceptions from Orchestrations Published as WCF Services</a>, tells you nothing about "how" to throw fault exceptions, except that they can be thrown and that you need to set <code>includeExceptionDetailInFaults</code> in the configuration (which I've already done).</p>
  
  <p>Does anyone have any suggestions on how this could be accomplished in BizTalk 2009?</p>