views:

505

answers:

1

My web sevices support flex/flash clients and, upon unhandeld exceptions, throw custom faults that extend System.ServiceModel.FaultException.

I have been informed that flex/flash can't read these custom faults if the the http response code is different from 200. This is documented as flex/flash bug: http://bugs.adobe.com/jira/browse/SDK-11841

I need to override the http return code upon unhandled exceptions. I have attempted to do this by including this code in global.asax (this hack has been documented as a work-around):

protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{
    if (Response.StatusCode != 200)
    { // fix response code for flex
        Response.StatusCode = 200;
    }
}

protected void Application_PreSendRequestHeaders(object sender, EventArgs e)
{    
    if (Response.StatusCode != 200)    
    { // fix response code for flex        
         Response.StatusCode = 200;
     }
}

But alas, my http return code comes back as 500 when an unhandled exception is encountered

Any ideas?

+1  A: 

You will probably need to add the following code before changing the response status code:

HttpContext.Current.ClearError()

That should keep your status code changes from getting overridden.

jellomonkey
I added this line to both Application_PreSendRequestHeaders() and Application_EndRequest(). Return Code is still 500 on a fault.Is is possible that this code (global.asax of the ServiceLayer Project) is not executing?
sympatric greg
You should really override the Application_Error if you want to clear the error. Additionally, are you sure some other error isn't occurring on the page after the error you are trying to trap?
jellomonkey