static void ReceiveAndProcessRequest(IMessageExchangeStream stream, Func <RequestMessage, ResponseMessage> incomingRequestProcessor)
        {
            var request = stream.Receive <RequestMessage>();

            if (request != null)
            {
                var response = InvokeAndWrapAnyExceptions(request, incomingRequestProcessor);
                stream.Send(response);
            }

            stream.SendNext();
            stream.ExpectProceeed();
        }
 void PrepareExchangeAsClient()
 {
     try
     {
         if (!identified)
         {
             stream.IdentifyAsClient();
             identified = true;
         }
         else
         {
             stream.SendNext();
             stream.ExpectProceeed();
         }
     }
     catch (Exception ex)
     {
         throw new ConnectionInitializationFailedException(ex);
     }
 }
        static void ReceiveAndProcessRequest(IMessageExchangeStream stream, Func<RequestMessage, ResponseMessage> incomingRequestProcessor)
        {
            var request = stream.Receive<RequestMessage>();
            if (request != null)
            {
                var response = InvokeAndWrapAnyExceptions(request, incomingRequestProcessor);
                stream.Send(response);
            }

            stream.SendNext();
            stream.ExpectProceeed();
        }