使用WebService自动捕获所有未处理的异常 [英] Capture all unhandled exceptions automatically with WebService

查看:465
本文介绍了使用WebService自动捕获所有未处理的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#WebService应用程序,其中我想捕获从应用程序抛出的所有未处理的异常。

I have a C# WebService application in which I want to capture all unhandled exceptions thrown from the application.

我该怎么做?

推荐答案

由于某种原因,Application_Error事件对Web Services不起作用(请参阅其他问题)。 Jeff Atwood先生本人已经在编码恐怖博客上发布了一些建议。

For some reason the Application_Error event does not fire for Web Services (see other question). Mr Jeff Atwood himself has posted some advice on the coding horror blog.

他写道:

*在每个WebService方法中放置一个try..catch。这些方法往往是围绕其他类的包装,所以这并不像听起来那么糟糕,但它还不是很好。


*使用Facade设计模式从父对象派生所有对象,基本上在.Execute方法上执行一个try..catch。呃,谢谢,但谢谢。


*编写一个自定义的SOAP扩展或HttpModule。这听起来很合理,但很难。如果这是一个很酷,重要的扩展或HttpModule,那么有没有人已经写过了?
* Put a try..catch around every WebService method. These methods tend to be wrappers around other classes, so this isn't quite as bad as it sounds, but it's still not good.
* use a Facade design pattern to derive all objects from parent objects that.. basically do a try..catch on the .Execute method. Uh, thanks but no thanks.
* Write a custom SOAP Extension or HttpModule. This sounds reasonable but.. hard. If it's such a cool, important extension or HttpModule, wouldn't someone have written it already?

这篇关于使用WebService自动捕获所有未处理的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆