This is a known issue in .Net - Application_Error never fires for a web service. Not sure if there's any reason it would be by design, but it just doesn't work.
Jeff Atwood had a post about this a few years ago, with the following ideas:
- Put a try-catch block around each web service method
- Use a facade design pattern and include the try-catch in parent objects
- Write a custom SOAP extension or HTTPModule
The only one I care for is the first one, even though it seems like a lot of work.
Better: HttpApplication.Error event:
Note:
If your Web application contains XML Web services, you cannot use the Error event for global exception handling of those services. The HTTP handler for XML Web services consumes any exception that occurs in an XML Web service and converts it to a SOAP fault before the Error being called. To handle XML Web service exceptions, build a SOAP extension to process Web service exceptions in a custom global exception handler. For more information, see Handling and Throwing Exceptions in XML Web Services.

本文探讨了ASP.NET中Web服务的异常处理难题,详细介绍了为何Application_Error事件不适用于Web服务异常捕获的原因,并提供了几种可能的解决方案,包括在每个Web服务方法中使用try-catch块等。
1万+

被折叠的 条评论
为什么被折叠?



