WCF:服务器端错误处理。最好的锻炼 [英] WCF: server-side error handling. best practice

查看:168
本文介绍了WCF:服务器端错误处理。最好的锻炼的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的WCF服务,并希望保持它的活动日志:跟踪,警告和错误消息。非常直接的方法是包装内的所有合约服务code的try / catch 部分和部分重新抛出服务合同错误异常。

I write WCF service and want to keep it's activity log: trace, warnings and error messages. The very straight-forward approach is to wrap all contract service code inside try/catch sections and write error messages from catch part rethrowing service contract error exceptions.

我想这将是很好,如果只安排一份code点到捕获所有未捕获的异常,而不是几十的try / catch 部分。这将是同样从该点写入合同法参数,提供详细的错误信息很有用。

I suppose it would be nice if there would be one code-point to catch all uncaught exceptions instead of dozens try/catch sections. It would be also useful to write contract method parameters from that point to provide detailed error information.

与WCF是否有可能?

Is it possible with WCF?

什么是组织错误处理内部WCF服务的最佳做法?

What is the best practice in organizing error handling inside WCF services?

感谢你在前进!

推荐答案

看一看的 IErrorHandler 接口

它允许实施者控制故障信息返回给调用者,并根据需要执行自定义错误处理,如登录

It allows an implementer to control the fault message returned to the caller and optionally perform custom error processing such as logging

您可以实现您的服务行为(见 IServiceBehavior接口接口),你的处理程序添加到 ChannelDispatcher 错误处理程序。

You can implement your service behavior (see IServiceBehavior interface) and add your handler to ChannelDispatcher error handlers.

请参阅 WCF异常处理IErrorHandler 了解更多的细节。

See WCF Exception Handling with IErrorHandler for more details.

这篇关于WCF:服务器端错误处理。最好的锻炼的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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