Exemplo n.º 1
0
        public void ProcessMessage(IMessage msg,
                                   ITransportHeaders reqHead,
                                   Stream reqStm,
                                   out ITransportHeaders respHead,
                                   out Stream respStm)
        {
            DBG.Info(null, "Being asked to process the serialized message!");
            //Console.WriteLine("ProcessMessage TID {0}", Thread.CurrentThread.GetHashCode());

            // Send the message across the pipe.
            PipeConnection _pipe = SendWithRetry(msg, reqHead, reqStm);

            respHead = null;
            respStm  = null;
            // Read response
            if (_pipe != null)
            {
                _pipe.BeginReadMessage();
                respHead = _pipe.ReadHeaders();
                respHead["__CustomErrorsEnabled"] = false;
                respStm = _pipe.ReadStream();
                _pipe.EndReadMessage();

                if (_pipeConnectionPool != null)
                {
                    _pipeConnectionPool.ReturnToPool(_pipe);
                }

                _pipe = null;
            }
        }
Exemplo n.º 2
0
        private void ReceiveCallback(Object state)
        {
            //Console.WriteLine("ReceiveCallback TID {0}", Thread.CurrentThread.GetHashCode());

            PipeConnectionCookie cookie = (PipeConnectionCookie)state;

            PipeConnection          _pipe     = cookie.pipe;
            IClientChannelSinkStack sinkStack = cookie.sinkStack;

            try
            {
                // Read response
                //
                _pipe.BeginReadMessage();

                ITransportHeaders responseHeaders = _pipe.ReadHeaders();
                responseHeaders["__CustomErrorsEnabled"] = false;

                Stream responseStream = _pipe.ReadStream();
                _pipe.EndReadMessage();

                if (_pipeConnectionPool != null)
                {
                    _pipeConnectionPool.ReturnToPool(_pipe);
                }

                _pipe = null;

                sinkStack.AsyncProcessResponse(responseHeaders, responseStream);
            }
            catch (Exception e)
            {
                try
                {
                    if (sinkStack != null)
                    {
                        sinkStack.DispatchException(e);
                    }
                }
                catch (Exception)
                {
                    // Fatal Error.. ignore
                }
            }
        } // ReceiveCallback
        private void ServerMain()
        {
            PipeConnection pipe = _pipe;

            _pipe = null;

            // Signal the guy to start waiting again... (w/ new event and endpoint)
            _event.Set();

            try
            {
                //TODO close the connection on a timeout
                //TODO if no activity for Nnnn milliseconds
                while (true)
                {
                    pipe.BeginReadMessage();
                    ITransportHeaders headers = pipe.ReadHeaders();
                    headers["__CustomErrorsEnabled"] = false;

                    Stream request = pipe.ReadStream();
                    pipe.EndReadMessage();

                    ServerChannelSinkStack stack = new ServerChannelSinkStack();
                    stack.Push(_transportSink, null);

                    IMessage          responseMsg;
                    ITransportHeaders responseHeaders;
                    Stream            responseStream;

                    ServerProcessing processing = _transportSink.NextChannelSink.ProcessMessage(stack,
                                                                                                null,
                                                                                                headers,
                                                                                                request,
                                                                                                out responseMsg,
                                                                                                out responseHeaders,
                                                                                                out responseStream);

                    // handle response
                    switch (processing)
                    {
                    case ServerProcessing.Complete:
                        // Send the response. Call completed synchronously.
                        stack.Pop(_transportSink);
                        WriteClientResponse(pipe, responseHeaders, responseStream);
                        break;

                    case ServerProcessing.OneWay:
                        break;

                    case ServerProcessing.Async:
                        stack.StoreAndDispatch(_transportSink, null);
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                DBG.Info(null, "Terminating client connection: " + e.Message);
                WriteExceptionResponse(pipe, e.ToString());
            }
            finally
            {
                if (pipe != null)
                {
                    pipe.Dispose();
                }
            }
        }