开发者

How to throw an exception on a web service in .net with custom message?

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 se开发者_JAVA技巧rvice, for example to know if the exception is a database connection error or a invalid key in header error


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


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜