public void ReturnChannel(ChannelPoolKey key, PooledChannel channel)
        {
            bool connectionIsStillGood = (channel.State == CommunicationState.Opened);
            bool newConnection         = false;

            lock (this.ThisLock)
            {
                newConnection = this.newChannels.Remove(channel);
            }

            if (newConnection)
            {
                if (connectionIsStillGood)
                {
                    this.channelPool.AddConnection(key, channel, ServiceDefaults.OpenTimeout);
                }
                else
                {
                    channel.Abort();
                }
            }
            else
            {
                this.channelPool.ReturnConnection(key, channel, connectionIsStillGood, ServiceDefaults.CloseTimeout);
            }
        }
 public PooledChannelTicket(ChannelManagerService service, ChannelManager.PooledChannel channel, ChannelPoolKey channelPoolKey, Guid workflowId, Guid logicalChannelId)
     : base()
 {
     this.service          = service;
     this.channel          = channel;
     this.channelPoolKey   = channelPoolKey;
     this.workflowId       = workflowId;
     this.logicalChannelId = logicalChannelId;
 }
        public PooledChannel TakeChannel(EndpointAddress address, Uri via, out ChannelPoolKey key)
        {
            PooledChannel channel = null;

            key = null;

            if (!this.closed)
            {
                ChannelFactoryReference factory = this.TakeChannelFactory(address);
                if (factory != null)
                {
                    bool channelCreated = false;
                    try
                    {
                        EndpointAddress cacheAddress = address;
                        if (factory.SupportsClientAuthentication)
                        {
                            cacheAddress = ChannelManagerHelpers.BuildCacheAddressWithIdentity(address);
                        }

                        channel = this.channelPool.TakeConnection(cacheAddress, via, ServiceDefaults.OpenTimeout, out key);
                        while (channel != null && channel.State != CommunicationState.Opened)
                        {
                            // Loop will exit because non-opened channels are returned with 'connectionStillGood=false'
                            this.channelPool.ReturnConnection(key, channel, false, ServiceDefaults.CloseTimeout);
                            channel = this.channelPool.TakeConnection(cacheAddress, via, ServiceDefaults.OpenTimeout, out key);
                        }

                        if (channel == null)
                        {
                            channel = this.CreateChannel(factory, address, via, out channelCreated);
                        }
                    }
                    finally
                    {
                        if (!channelCreated)
                        {
                            this.ReturnChannelFactory(address, factory);
                        }
                    }
                }
            }

            return(channel);
        }
 public PooledChannelTicket(ChannelManagerService service, ChannelManager.PooledChannel channel, ChannelPoolKey channelPoolKey, Guid workflowId, Guid logicalChannelId)
     : base()
 {
     this.service = service;
     this.channel = channel;
     this.channelPoolKey = channelPoolKey;
     this.workflowId = workflowId;
     this.logicalChannelId = logicalChannelId;
 }
        public PooledChannel TakeChannel(string endpointName, Type contractType, string customAddress, out ChannelPoolKey key)
        {
            EndpointAddress cacheAddress = ChannelManagerHelpers.BuildCacheAddress(endpointName, contractType);
            Uri             via          = (customAddress != null) ? new Uri(customAddress) : defaultViaUri;

            if (this.closed)
            {
                key = null;
                return(null);
            }

            this.endpointMappings[cacheAddress] = new KeyValuePair <string, Type>(endpointName, contractType);

            return(this.TakeChannel(cacheAddress, via, out key));
        }