码迷,mamicode.com
首页 > 其他好文 > 详细

WCF ChannelFactory

时间:2015-05-19 22:31:52      阅读:203      评论:0      收藏:0      [点我收藏+]

标签:

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

WCF ChannelFactory

标签:

原文地址:http://www.cnblogs.com/fery/p/4515683.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!