在过去(.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/bcaraway/archive/2008/07/06/123622.aspx
关于c# - WCF 4 关闭客户端代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4323266/