• 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
  • 相关阅读:
    PYTOHN1.day14
    PYTHON1.day13
    PYTHON1.day12
    PYTHON1.day11(n)
    PYTHON1.day10
    PYTHON1.day09
    PYTHON1.day08
    同步代码块 synchronized
    守护线程
    休眠线程
  • 原文地址:https://www.cnblogs.com/fery/p/4515683.html
Copyright © 2020-2023  润新知