c# - WCF 4 关闭客户端代理

标签 c# wcf wcf-4

在过去(.net framework 3.5)我们需要小心关闭 WCF 客户端代理。

在 WCF 4 中,Close 在客户端不可用。但它在代理内部可用。

public class ServiceProxy : System.ServiceModel.ClientBase<IService>, ILoginService
{
}

是否不再需要关闭客户端代理?或者我们该怎么做?

最佳答案

WCF Proxy need to be closed explicitly and if you are using the using() statement, you have the possibility of loosing the original exception. You can find details about this issue in the following posts.

发件人:http://geekswithblogs.net/SudheersBlog/archive/2009/09/01/134430.aspx

http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/b95b91c7-d498-446c-b38f-ef132989c154 http://geekswithblogs.net/marcel/archive/2007/05/01/112159.aspx

推荐的最佳做法是在客户端使用完代理后始终关闭代理,因为关闭代理会终止与服务的 session 并关闭连接。

或者,您可以使用代理的 Dispose() 方法来关闭它。 Dispose()方法的好处是即使遇到异常也可以使用using语句调用

检查

http://geekswithblogs.net/SoftwareDoneRight/archive/2008/05/23/clean-up-wcf-clients--the-right-way.aspx

http://geekswithblogs.net/bcaraway/archive/2008/07/06/123622.aspx

关于c# - WCF 4 关闭客户端代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4323266/

相关文章:

c# - Windows 服务无法从 App.config 读取参数

.net - WCF 是否具有与 MVC 的 [Authorize] 属性等效的属性?

sql - 关于数据库变更的通知

c# - 升级 .NET 后未调用 WCF 异步 'End' 方法

.net - 如何在更改 WCF 服务应用程序项目中的命名空间时运行 WCF 服务?

c# - 'System.Int32' 类型的对象无法转换为 'System.Web.Security.Cryptography.Purpose' 类型

C# OpenXML 判断段落是否为隐藏文本

c# - 使用 WCF 发现跨域发现非 WCF Windows 服务

wcf - WCF 4 服务的平面 WSDL

c# - SharpPcap - 从数据包中提取信息的数据包捕获问题