public ChannelManager(ChannelPoolSettings settings, IList <ServiceEndpoint> endpoints)
        {
            this.channelPool  = new PooledChannelPool(settings);
            this.factoryCache = new Dictionary <EndpointAddress, ChannelFactoryReference>();

            this.newChannels = new List <PooledChannel>();

            this.endpoints        = new Dictionary <EndpointAddress, ServiceEndpoint>();
            this.endpointMappings = Hashtable.Synchronized(new Hashtable());

            if (endpoints != null)
            {
                foreach (ServiceEndpoint endpoint in endpoints)
                {
                    if (endpoint != null)
                    {
                        EndpointAddress cacheAddress = null;
                        if (endpoint.Contract.ContractType != null)
                        {
                            cacheAddress = ChannelManagerHelpers.BuildCacheAddress(endpoint.Name, endpoint.Contract.ContractType);
                        }
                        else
                        {
                            cacheAddress = ChannelManagerHelpers.BuildCacheAddress(endpoint.Name, endpoint.Contract.Name);
                        }
                        this.endpoints.Add(cacheAddress, endpoint);
                    }
                }
            }
        }
        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));
        }