private TContract GetDuplexChannelInternal <TContract>(InstanceContext instanceContext, ContractInfo contract) where TContract : class
        {
            IProxyChannelManager <TContract> proxyChannelManager = GetProxyChannelManager <TContract>(contract.Key);

            if (proxyChannelManager == null)
            {
                lock (_proxyChannelManagerContainerLocker)
                {
                    proxyChannelManager = GetProxyChannelManager <TContract>(contract.Key);
                    if (proxyChannelManager == null)
                    {
                        proxyChannelManager = ProxyChannelManagerFactory.CreateDuplex <TContract>(instanceContext, contract);
                        RegisterProxyChannelManager(proxyChannelManager, contract.Key);
                    }
                }
            }

            return(proxyChannelManager.GetChannel());
        }
        private void GetDuplexChannelAsyncInternal <TContract>(InstanceContext instanceContext, ContractInfo contract, EventHandler <ChannelEstablishedEventArgs> callback) where TContract : class
        {
            IProxyChannelManager <TContract> proxyChannelManager = GetProxyChannelManager <TContract>(contract.Key);

            if (proxyChannelManager == null)
            {
                lock (_proxyChannelManagerContainerLocker)
                {
                    proxyChannelManager = GetProxyChannelManager <TContract>(contract.Key);
                    if (proxyChannelManager == null)
                    {
                        proxyChannelManager = ProxyChannelManagerFactory.CreateDuplex <TContract>(instanceContext, contract);
                        RegisterProxyChannelManager(proxyChannelManager, contract.Key);
                    }
                }
            }

            SaveAsyncChannelEstablishedCallback(contract.Key, callback);
            proxyChannelManager.GetChannelAsync();
        }