在我当前的生产代码中,根据关于msdn的文档,创建客户机的方法如下
using (WebChannelFactory<IServiceInterface> cf
= new WebChannelFactory<IServiceInterface>("http://service.url"))
{
IServiceInterface client = cf.CreateChannel();
client.CallTheMethod();
}考虑到我有这个接口:
public interface IServiceInterface
{
void CallTheMethod();
}但是,我注意到WebChannelFactory创建的对象客户机也实现了IDisposable。所以我也要处理这个对象。我没有找到别的方法,除了:
using (WebChannelFactory<IServiceInterface> cf
= new WebChannelFactory<IServiceInterface>("http://service.url"))
using(IDisposable client = (IDisposable)cf.CreateChannel())
{
((IServiceInterface)client).CallTheMethod();
}我觉得这很难看。因此:
https://stackoverflow.com/questions/5746998
复制相似问题