Exemplo n.º 1
0
        internal static TransientChannelTicket CreateTransientChannel(LogicalChannel logicalChannel)
        {
            DiagnosticUtility.DebugAssert(logicalChannel != null, "logical channel cannot be null");

            ChannelFactory factory       = null;
            IChannel       channel       = null;
            bool           channelOpened = false;

            try
            {
                factory       = ChannelManagerHelpers.CreateChannelFactory(logicalChannel.ConfigurationName, logicalChannel.ContractType);
                channel       = ChannelManagerHelpers.CreateChannel(logicalChannel.ContractType, factory, logicalChannel.CustomAddress);
                channelOpened = true;
            }
            finally
            {
                if (!channelOpened)
                {
                    if (channel != null)
                    {
                        ChannelManagerHelpers.CloseCommunicationObject(channel);
                    }
                    if (factory != null)
                    {
                        ChannelManagerHelpers.CloseCommunicationObject(factory);
                    }
                }
            }

            return(new TransientChannelTicket(channel, factory));
        }
        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);
        }