C# 使用WebChannelFactory创建后处理客户端

C# 使用WebChannelFactory创建后处理客户端,c#,wcf,dispose,webchannelfactory,C#,Wcf,Dispose,Webchannelfactory,根据我目前的生产代码,创建客户机的方法如下 using (WebChannelFactory<IServiceInterface> cf = new WebChannelFactory<IServiceInterface>("http://service.url")) { IServiceInterface client = cf.CreateChannel(); client.CallTheMethod(); } 然而,我注意到WebCha

根据我目前的生产代码,创建客户机的方法如下

using (WebChannelFactory<IServiceInterface> cf
      = new WebChannelFactory<IServiceInterface>("http://service.url"))
{
    IServiceInterface client = cf.CreateChannel();
    client.CallTheMethod();
}
然而,我注意到WebChannelFactory创建的对象客户端也实现了IDisposable。所以我也要处理这个对象。我没有找到别的办法,除了:

using (WebChannelFactory<IServiceInterface> cf
      = new WebChannelFactory<IServiceInterface>("http://service.url"))
using(IDisposable client = (IDisposable)cf.CreateChannel())
{
    ((IServiceInterface)client).CallTheMethod();
}
我觉得这很难看。因此:

我真的需要处理它吗?我的意思是,如果工厂保留对它创建的每个对象的引用,那么当您处理工厂时,它可能会被处理? 如果是,你有更好的方法吗?
这是一个非常复杂的问题。即使自己承认,处置渠道工厂是一个糟糕的设计,它被多次更改,所以简短的回答是不,你需要使用一些替代品


这里有一个处理的方法。

你没有真正回答我的问题,但你给了我很好的阅读,我接受你的回答。谢谢
using (WebChannelFactory<IServiceInterface> cf
      = new WebChannelFactory<IServiceInterface>("http://service.url"))
using(IDisposable client = (IDisposable)cf.CreateChannel())
{
    ((IServiceInterface)client).CallTheMethod();
}