简体   繁体   English

服务级别的WCF REST异常处理不是全局的

[英]WCF REST Exception handling at service level NOT Globally

I am working on a WCF service exposes its functionality in a RESTful format. 我正在使用WCF服务,以RESTful格式公开其功能。 Each services adhere to SOA format and I need flexibility in the way the services are deployed. 每个服务都遵循SOA格式,我需要在服务部署方式上具有灵活性。 So when it comes to the exception handling, I want them to be handled at a single point with in the service level, rather than handling at global level. 因此,当涉及到异常处理时,我希望在服务级别上对它们进行单点处理,而不是在全局级别上进行处理。 I want to avoid writing try/catch block for each service API.Is it possible to handle the exceptions in a one common place specific to each service. 我想避免为每个服务API编写try / catch块,是否有可能在每个服务特定的一个公共位置处理异常。 In other words, is there any method which I can hookup to in the WCF call stack where all the exceptions can be handled. 换句话说,我可以在WCF调用堆栈中连接任何方法,在其中可以处理所有异常。

I've used custom behavior extensions to do this sort of thing. 我已经使用自定义行为扩展来做这种事情。 Basically, you create a new class that implements IErrorHandler and then put in your code for handling the error how you want and for what dispatch levels (IServiceBehavior, IEndpointBehavior, IContractBehavior, etc). 基本上,您将创建一个实现IErrorHandler的新类,然后将代码放入您的代码中,以所需的方式以及按何种调度级别(IServiceBehavior,IEndpointBehavior,IContractBehavior等)处理错误。 Add the error handler to the service behaviors and you are set. 将错误处理程序添加到服务行为中,您便已设置好。

Here is an example I found online of it to use as a starting point (you can also set behaviors in config file): http://wcfpro.wordpress.com/2010/11/18/wcf-extensions-error-handler/ 这是我在网上找到的用作起点的示例(您也可以在配置文件中设置行为): http : //wcfpro.wordpress.com/2010/11/18/wcf-extensions-error-handler/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM