且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么我们使用Fault契约而不是Try-catch块?

更新时间:2021-12-19 07:20:01

阅读以下文章



故障合同 - 处理WCF和A中的错误非常简单的WCF服务实现 [ ^ ]


用最简单的术语来说,Try / Catch块是处理异常的本地方式 - 如果可以的话立即与您的用户进行交互,然后您只需使用它并可能显示错误消息。



故障合同可用于程序与服务交互的地方,并允许服务将异常的详细信息发送回客户端进程(以受控方式) )
In its simplest terms a Try/Catch block is a "local" way of handling exceptions - if you can immediately interact with your user then you would just use this and perhaps display an error message.

A Fault Contract can be used where a program is interacting with a service and allows the service to send details of an exception back to the client process (in a controlled manner)


由于异常屏蔽,您应该使用故障合同。



在Windows Communication Foundation(WCF)中,未向客户端应用程序发送未知异常,以防止服务实现的详细信息逃避服务的安全边界。 br $>


JAFC
You should use a fault contract because of exception shielding.

In Windows Communication Foundation (WCF), unknown exceptions are not sent to the client application to prevent details of the service implementation from escaping the secure boundary of the service.

JAFC