title: WCF 4.0 - Returning JSON WebFaultException with REST Service Template
body: <p>I am using the WCF REST Service Template 40(CS). I am throwing WebFaultExceptions as such:</p>
  
  <pre><code>throw new WebFaultException&lt;string&gt;("Error Message", HttpStatusCode.BadRequest);
  </code></pre>
  
  <p>However, when I test this with my client, everything is being returned as a Http Status Code of 500 and the response is XML. I can see the error message in the XML response. When I make a call correctly, I get a 200 response and the response is in JSON which is correct given the way my config and ServiceContract are setup.</p>
  
  <p>The only way I can get the HTTP Status Code to be 400 for the Bad Request is to do this:</p>
  
  <pre><code>WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.BadRequest;
  </code></pre>
  
  <p>I still cannot get the exception to return as JSON.</p>
  
  <p><strong>Edit</strong> Adding signature for more information:</p>
  
  <pre><code>[OperationContract]
  [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json, UriTemplate = "myendpoint")]
  </code></pre>
  
  <p>Is there an easy way to accomplish this?</p>