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 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); }
PooledChannel CreateChannel(ChannelFactoryReference factory, EndpointAddress address, Uri via, out bool channelCreated) { PooledChannel pooledChannel = null; channelCreated = false; IChannel channel = ChannelManagerHelpers.CreateChannel(factory.ContractType, factory.ChannelFactory, (via == defaultViaUri) ? null : via.ToString()); if (channel != null) { pooledChannel = new PooledChannel(this, factory, address, channel); lock (this.ThisLock) { this.newChannels.Add(pooledChannel); } channelCreated = true; } return(pooledChannel); }