Bap*_*net 2 c# wcf dispose webchannelfactory
在我目前的生产代码中,根据msdn上的文档,创建客户端的方法就是这样
using (WebChannelFactory<IServiceInterface> cf
= new WebChannelFactory<IServiceInterface>("http://service.url"))
{
IServiceInterface client = cf.CreateChannel();
client.CallTheMethod();
}
Run Code Online (Sandbox Code Playgroud)
鉴于我有这个界面:
public interface IServiceInterface
{
void CallTheMethod();
}
Run Code Online (Sandbox Code Playgroud)
但是我注意到WebChannelFactory创建的对象客户端也实现了IDisposable.所以我也要处理这个对象.我没有找到任何其他方式:
using (WebChannelFactory<IServiceInterface> cf
= new WebChannelFactory<IServiceInterface>("http://service.url"))
using(IDisposable client = (IDisposable)cf.CreateChannel())
{
((IServiceInterface)client).CallTheMethod();
}
Run Code Online (Sandbox Code Playgroud)
我发现这很难看.所以:
| 归档时间: |
|
| 查看次数: |
927 次 |
| 最近记录: |