关闭和处理 WCF 服务 [英] Closing and Disposing a WCF Service

查看:35
本文介绍了关闭和处理 WCF 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ICommunicationObject 上的 Close 方法可以抛出两种类型的异常,如 MSDN 概述此处.我理解为什么 Close 方法会抛出这些异常,但我不明白的是为什么服务代理上的 Dispose 方法调用 Close 周围没有 try 的方法.您的 Dispose 方法不是您想要确保不抛出任何异常的地方吗?

The Close method on an ICommunicationObject can throw two types of exceptions as MSDN outlines here. I understand why the Close method can throw those exceptions, but what I don't understand is why the Dispose method on a service proxy calls the Close method without a try around it. Isn't your Dispose method the one place where you want make sure you don't throw any exceptions?

推荐答案

这似乎是 .NET 代码中的常见设计模式.这里引用了 框架设计指南

It seems to be a common design pattern in .NET code. Here is a citation from Framework design guidelines

考虑提供 Close() 方法,以及 Dispose(),如果 close 是该领域的标准术语.这样做时,重要的是使 Close 实现与 Dispose ...

Consider providing method Close(), in addition to the Dispose(), if close is standard terminology in the area. When doing so, it is important that you make the Close implementation identical to Dispose ...

这是一篇博文,您可以在其中找到此 System.ServiceModel.ClientBase 设计问题的解决方法

Here is a blog post in which you can find workaround for this System.ServiceModel.ClientBase design problem

这篇关于关闭和处理 WCF 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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