How to dispose of a System.ServiceModel.ClientBase<TChannel>?

I'm using a class that extends ClientBase<>:

interface IService {}
class MyServiceClient : ClientBase<IService> {}

The issue I run into is that FxCop complains that a class with MyServiceClient as a member variable should also implement IDisposable and dispose of MyServiceClient.

ClientBase has an explicit implementation of Dispose(), which means a simple MyServiceClient.Dispose() doesn't compile. I have to explicitly cast to IDisposable. Why is that? Is it a signal that I shouldn't use Dispose()? Should I use Close() instead?


In Close and Dispose - which to call? is suggested that Close and Dispose should have the same implementation. Here is an example wrapper class (usage) which calls Close in the Dispose function. So it seems fine to call Close.


I wraped my Base inheritor in using bloc and it works. Like this:

using (var someClient = new SomeClient(_netTcpBinding,_endpointAddress))
{
    return someClient.SomeMethod();
}

But when i open cmd and enter netstat -a -n -p TCP i saw 在这里输入图像描述

The answer I found here http://sahilmalik.blogspot.ru/2005/11/sockets-and-timewait.html and I rewrote my code like in this case http://marcgravell.blogspot.ru/2008/11/dontdontuse-using.html

链接地址: http://www.djcxy.com/p/54034.html

上一篇: 我应该为流对象调用Close()还是Dispose()?

下一篇: 如何处置System.ServiceModel.ClientBase <TChannel>?