Search code examples
c#wcfwcf-4

WCF 4 close client proxy


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?


Solution

  • 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