WCF 4关闭客户端代理

发布于 2024-10-05 18:32:58 字数 246 浏览 5 评论 0原文

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

在 WCF 4 中,客户端无法执行“关闭”操作。但它在代理内部可用。

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

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

In the old days (.net framework 3.5) we need to be careful to close the WCF client proxies.

In WCF 4 the Close is not available from the client. But it is available inside the proxy.

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

Is closing the client proxy no longer required? Or how do we do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请你别敷衍 2024-10-12 18:32:58

WCF 代理需要显式关闭,如果您使用 using() 语句,则有可能丢失原始异常。
您可以在以下帖子中找到有关此问题的详细信息。

来自: 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

建议的最佳实践是在客户端使用完代理后始终关闭代理,因为关闭代理会终止与服务的会话并关闭连接。

或者,您可以使用代理的 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

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.

From: 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

It is a recommended best practice to always close the proxy when the client is done using it, because closing the proxy terminates the session with the service and closes the connection.

Alternatively, you can use the Dispose() method of the proxy to close it. The advantage of the Dispose() method is that you can use the using statement to call it even in the face of exceptions

check

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文