global.asax Application_Error method does not catch exceptions thrown by ASMX service?

1 篇文章 0 订阅
1 篇文章 0 订阅

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值