开发者

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 开发者_如何学Cshouldn'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

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜