global.asax Application_Error method does not catch exceptions thrown by ASMX service?
来源:互联网 发布:部落冲突天鹰火炮数据 编辑:程序博客网 时间:2024/04/20 22:57
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.
For anyone looking for Microsoft's word on this topic, see here: "Handling and Throwing Exceptions in XML Web Services".
This is the relevant section:
A Web application can be comprised of multiple XML Web services, however the Application_Error event within the Global.asax file cannot be used for global exception handling. The HttpHandler for XML Web services consumes any exception that occurs while an XML Web service is executing and turns it into a SOAP fault prior to the Application_Error event is called.
- global.asax Application_Error method does not catch exceptions thrown by ASMX service?
- Global.asax中的Application_Error事件不执行
- Global.asax中Application_Error得到的“文件不存在”错误
- Handling Application_Error in ASP.NET app's global.asax
- 利用Global.asax的Application_Error实现错误记录,错误日志
- exceptions be caught by catch
- ASP.NET MVC中注册Global.asax的Application_Error事件处理全局异常
- The following exceptions are thrown by certain C# operations.
- GLOBAL.ASAX
- Global.asax
- Global.asax
- Global.asax
- Global.asax
- global.asax
- Global.asax
- global.asax
- global.asax
- “Parser Error Message: Could not load type” in Global.asax
- 解決Oracle中文亂碼問題
- SIP Presence
- 变量名 @XXX 已声明。变量名在批查询或存储过程内部必须唯一
- 教务系统初期
- Android联系人读取操作笔记
- global.asax Application_Error method does not catch exceptions thrown by ASMX service?
- #pragma 指令
- 关于任务栏上android模拟器的小机器人图标不显示的问题的解决
- 浏览器中的data类型的URL格式
- 回调函数总结
- 三谈Iframe自适应高度 By 由校
- 电脑显示器设置
- 程序员技术练级攻略
- XML解析