public static class WcfExtensions
{
public static void Using<T>(this T client, Action<T> work)
where T : ICommunicationObject
{
try
{
work(client);
client.Close();
}
catch (CommunicationException e) { client.Abort(); } catch (TimeoutException e)
{
client.Abort();
}
catch (Exception e)
{
client.Abort();
throw;
}
}
}
Then use this instead of the using keyword:
new SomeClient().Using(channel => { channel.Login(username, password); });
Or if you are using ChannelFactory
then:
new ChannelFactory<ISomeService>().Using(channel => {
channel.Login(username, password);
});
Reference: http://www.codeproject.com/Tips/197531/Do-not-use-using-for-WCF-Clients
http://www.codeproject.com/Articles/361660/WCF-Proxy-Manager-Going-Configless
转载于:https://www.cnblogs.com/fery/p/4515683.html
最后
以上就是火星上白羊最近收集整理的关于WCF ChannelFactory的全部内容,更多相关WCF内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复