/// <summary>
        /// Closes the current connection.
        /// </summary>
        public void CloseConnection()
        {
            CleanupHost();

            if (m_Receiver != null)
            {
                m_Receiver       = null;
                m_AttachEndpoint = null;
            }

            m_Diagnostics.Log(
                LevelToLog.Trace,
                CommunicationConstants.DefaultLogTextPrefix,
                string.Format(
                    CultureInfo.InvariantCulture,
                    "Closed channel of type: {0}",
                    m_Template.GetType().Name));
        }
        /// <summary>
        /// Opens the channel and provides information on how to connect to the given channel.
        /// </summary>
        /// <param name="receiver">The object that receives the transmissions from the remote endpoint.</param>
        /// <param name="attachEndpoint">The function that attaches an endpoint to the service host.</param>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="receiver"/> is <see langword="null" />.
        /// </exception>
        /// <exception cref="ArgumentNullException">
        ///     Thrown if <paramref name="attachEndpoint"/> is <see langword="null" />.
        /// </exception>
        /// <returns>The URL of the newly opened channel.</returns>
        public Uri OpenChannel(IReceiveInformationFromRemoteEndpoints receiver, Func <ServiceHost, ServiceEndpoint> attachEndpoint)
        {
            {
                Lokad.Enforce.Argument(() => receiver);
                Lokad.Enforce.Argument(() => attachEndpoint);
            }

            if (m_Receiver != null)
            {
                CloseConnection();
            }

            m_Receiver       = receiver;
            m_AttachEndpoint = attachEndpoint;

            var uri = m_Template.GenerateNewChannelUri();

            return(ReopenChannel(uri));
        }