zoukankan      html  css  js  c++  java
  • WCF ChannelFactory

    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
  • 相关阅读:
    B站使用总结
    安装国外浏览器的好处
    查看网页源代码
    如何下载bilibili上面的视频
    11.27
    11.26
    11.25
    11.24获取时间
    11.23
    11.21
  • 原文地址:https://www.cnblogs.com/fery/p/4515683.html
Copyright © 2011-2022 走看看