Пример #1
0
        internal void InternalProcessMessage(Stream network_stream)
        {
            try {
                string uri;
                SimpleMessageFormat.MessageType msg_type;
                MemoryStream msg_stream;

                msg_stream = SimpleMessageFormat.ReceiveMessageStream(network_stream,
                                                                      out msg_type, out uri);
                if (msg_type != SimpleMessageFormat.MessageType.Request)
                {
                    throw new RemotingException("received wrong message type");
                }

                TransportHeaders headers = new TransportHeaders();
                headers ["_requestUri"] = uri;

                IMessage          resp_message;
                ITransportHeaders resp_headers;
                Stream            resp_stream;
                ServerProcessing  res = next_sink.ProcessMessage(null, null, headers, msg_stream,
                                                                 out resp_message, out resp_headers,
                                                                 out resp_stream);

                switch (res)
                {
                case ServerProcessing.Complete:

                    Exception e = ((IMethodReturnMessage)resp_message).Exception;
                    if (e != null)
                    {
                        // we handle exceptions in the transport channel
                        SimpleMessageFormat.SendExceptionMessage(network_stream, e.ToString());
                    }
                    else
                    {
                        // send the response
                        SimpleMessageFormat.SendMessageStream(network_stream,
                                                              (MemoryStream)resp_stream,
                                                              SimpleMessageFormat.MessageType.Response,
                                                              null);
                    }
                    break;

                case ServerProcessing.Async:
                case ServerProcessing.OneWay:
                    throw new NotImplementedException();
                }
            } catch (Exception e) {
                SimpleMessageFormat.SendExceptionMessage(network_stream, e.ToString());
            }
        }
Пример #2
0
        public void ProcessMessage(IMessage msg,
                                   ITransportHeaders requestHeaders,
                                   Stream requestStream,
                                   out ITransportHeaders responseHeaders,
                                   out Stream responseStream)
        {
            // get a network stream
            if (network_stream == null)
            {
                tcpclient.Connect(host, port);
                network_stream = tcpclient.GetStream();
            }

            // send the message
            SimpleMessageFormat.SendMessageStream(network_stream, (MemoryStream)requestStream,
                                                  SimpleMessageFormat.MessageType.Request,
                                                  object_uri);

            // read the response fro the network an copy it to a memory stream
            SimpleMessageFormat.MessageType msg_type;
            string       uri;
            MemoryStream mem_stream = SimpleMessageFormat.ReceiveMessageStream(network_stream, out msg_type, out uri);

            // close the stream
            //tcpclient.Close ();

            switch (msg_type)
            {
            case SimpleMessageFormat.MessageType.Response:
                //fixme: read response message
                responseHeaders = null;

                responseStream = mem_stream;

                break;

            default:
                throw new Exception("unknown response mesage header");
            }
        }