views:

105

answers:

3

How do I throw a custom exception in a C# web service so that flex reads the error on fault?

I tried simply throwing an exception like this

throw new Exception("invalid key");

But FaultEvent couldn't decode the message in flex.

Edit: What I really want to do is for flex to differentiate exceptions in the web service, for example to know if the exception is a database connection error or a invalid key in header error

+2  A: 

Not sure but this might help; Jeff Atwood says .NET doesnt throw very good SOAP exceptions.

zac
I did read this and didn't get it at first but now I do, thanks
sergiogx
+1  A: 

You'll need to somehow make the .net webserver return a normal soap exception response, but using HTTP code 200 instead of of 500 (the standard). This is because when the server responds with a 500, the browser strips all the useful information before it gives the details to the Flash Player plugin. On Java, you can just do this with a filter, but I'm not sure about how to go about it in .net

Sophistifunk
+1  A: 

In .net webserver, you can define your own SoapExtention class and override the ProcessMessage function, at stage "SoapMessageStage.BeforeSerialize", you can use following code to change http status code:

                    HttpContext currrentContext = HttpContext.Current;
                    currrentContext.Response.StatusCode = 200;

Mike

Mike