public void OpenConnection(Action <MessageContext> responseMessageHandler)
        {
            using (EneterTrace.Entering())
            {
                if (responseMessageHandler == null)
                {
                    throw new ArgumentNullException("responseMessageHandler is null.");
                }

                using (ThreadLock.Lock(myConnectionManipulatorLock))
                {
                    try
                    {
                        mySender = new NamedPipeSender(myInputConnectorAddress, myTimeout);

                        myResponseMessageHandler = responseMessageHandler;
                        myResponseReceiver       = new NamedPipeReceiver(myOutputConnectorAddress, 1, myTimeout, mySecurity);
                        myResponseReceiver.StartListening(HandleResponseMessages);

                        // Send the open connection request.
                        object anEncodedMessage = myProtocolFormatter.EncodeOpenConnectionMessage(myOutputConnectorAddress);
                        mySender.SendMessage(anEncodedMessage);
                    }
                    catch
                    {
                        CloseConnection();
                        throw;
                    }
                }
            }
        }
        private void CloseConnection(string outputConnectorAddress, NamedPipeSender clientContext)
        {
            using (EneterTrace.Entering())
            {
                try
                {
                    object anEncodedMessage = myProtocolFormatter.EncodeCloseConnectionMessage(outputConnectorAddress);
                    clientContext.SendMessage(anEncodedMessage);
                }
                catch (Exception err)
                {
                    EneterTrace.Warning("failed to send the close message.", err);
                }

                clientContext.Dispose();
            }
        }