Note that there are some explanatory texts on larger screens.

plurals
  1. POWCF Always Returns 400 for Exceptions
    primarykey
    data
    text
    <p>I have a RESTful WCF service and I've implemented an ErrorHandler such as the following:</p> <pre><code>public class MyErrorHandler : IErrorHandler, IServiceBehavior { // OMITTED: IServiceBehavior Members public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { DoSomeCustomLogging(error); WebOperationContext ctx = WebOperationContext.Current; ctx.OutgoingResponse.StatusCode = HttpStatusCode.InternalServerError; } } </code></pre> <pre> <code> public class MyErrorHandlerElement : BehaviorExtensionElement { protected override object CreateBehavior() { return new MyErrorHandler(); } public override Type BehaviorType { get { return typeof(MyErrorHandler); } } } </code> </pre> <p>It's hooked up in my web.config like so:</p> <pre><code>&lt;system.serviceModel&gt; &lt;behaviors&gt; &lt;endpointBehaviors&gt; &lt;behavior name="Rest"&gt; &lt;webHttp /&gt; &lt;/behavior&gt; &lt;/endpointBehaviors&gt; &lt;/behaviors&gt; &lt;extensions&gt; &lt;behaviorExtensions&gt; &lt;add name ="errorHandler" type="ACME.MyErrorHandlerElement, ACME.MyErrorHandler"/&gt; &lt;/behaviorExtensions&gt; &lt;/extensions&gt; &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" /&gt; &lt;standardEndpoints&gt; &lt;webHttpEndpoint&gt; &lt;standardEndpoint name="" faultExceptionEnabled="false" helpEnabled="false" automaticFormatSelectionEnabled="true" /&gt; &lt;/webHttpEndpoint&gt; &lt;/standardEndpoints&gt; &lt;/system.serviceModel&gt; </code></pre> <p>For some reason, if my service throws an exception, 400 is returned to the client instead of 500. Any ideas why?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload