在我当前的生产代码中,根据关于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();
}我觉得这很难看。因此:
发布于 2011-04-21 16:37:00
这是一个非常复杂的问题。即使是微软的自己承认,处理通道工厂也是一个错误的设计,它被多次更改,所以简短的回答是否定的,您需要使用一些替代它的方法。
下面是一个要处理的替代方案方法。
https://stackoverflow.com/questions/5746998
复制相似问题