private async Task EnsureChannelAsync(FramingConnection connection)
 {
     if (_replyChannel == null)
     {
         using (await _lock.TakeLockAsync())
         {
             if (_replyChannel == null)
             {
                 var be  = connection.ServiceDispatcher.Binding.CreateBindingElements();
                 var tbe = be.Find <TransportBindingElement>();
                 ITransportFactorySettings settings = new NetFramingTransportSettings
                 {
                     CloseTimeout           = connection.ServiceDispatcher.Binding.CloseTimeout,
                     OpenTimeout            = connection.ServiceDispatcher.Binding.OpenTimeout,
                     ReceiveTimeout         = connection.ServiceDispatcher.Binding.ReceiveTimeout,
                     SendTimeout            = connection.ServiceDispatcher.Binding.SendTimeout,
                     ManualAddressing       = tbe.ManualAddressing,
                     BufferManager          = connection.BufferManager,
                     MaxReceivedMessageSize = tbe.MaxReceivedMessageSize,
                     MessageEncoderFactory  = connection.MessageEncoderFactory
                 };
                 _replyChannel      = new ConnectionOrientedTransportReplyChannel(settings, null, _servicesScopeFactory.CreateScope().ServiceProvider);
                 _channelDispatcher = await connection.ServiceDispatcher.CreateServiceChannelDispatcherAsync(_replyChannel);
             }
         }
     }
 }
            private bool TransferUpgrade()
            {
                ConnectionOrientedTransportReplyChannel currentChannel = (ConnectionOrientedTransportReplyChannel)base.GetCurrentChannel();

                if (currentChannel == null)
                {
                    return(false);
                }
                return(currentChannel.TransferUpgrade(this.upgrade));
            }
            // used to decouple our channel and listener lifetimes
            bool TransferUpgrade()
            {
                ConnectionOrientedTransportReplyChannel singletonChannel = (ConnectionOrientedTransportReplyChannel)base.GetCurrentChannel();

                if (singletonChannel == null)
                {
                    return(false);
                }
                else
                {
                    return(singletonChannel.TransferUpgrade(this.upgrade));
                }
            }