예제 #1
0
        public void ReceiveResponse(out ITransportHeaders responseHeaders, out Stream responseStream)
        {
            // transport signature
            if (!MatchPreamble())
            {
                BinaryWireProtocol.ThrowException(BinaryWireProtocol.StatusCode.InvalidMessageFormat);
            }
            // operation opcode
            byte operation = _reader.ReadByte();

            if (operation != BinaryWireProtocol.OperationType.Reply)
            {
                BinaryWireProtocol.ThrowException(BinaryWireProtocol.StatusCode.InvalidMessageFormat);
            }
            // content length
            int contentLength = _reader.ReadInt32();

            // response headers
            responseHeaders = ReadHeaders();
            // set special headers
            responseHeaders[BinaryWireProtocol.WellKnownHeaders.ConnectionId] = _connectionId;

            // create stream for response reading
            if (contentLength == -1)
            {
                responseStream = new ChunkedReadStream(_bufferedStream);
            }
            else
            {
                responseStream = new FixedReadStream(_bufferedStream, contentLength);
            }
        }
예제 #2
0
        public void ReceiveRequest(out ITransportHeaders requestHeaders, out Stream requestStream)
        {
            // transport signature
            if (!MatchPreamble())
            {
                BinaryWireProtocol.ThrowException(BinaryWireProtocol.StatusCode.InvalidMessageFormat);
            }
            // operation opcode
            byte operation = _reader.ReadByte();

            if (operation != BinaryWireProtocol.OperationType.Request && operation != BinaryWireProtocol.OperationType.OneWayRequest)
            {
                BinaryWireProtocol.ThrowException(BinaryWireProtocol.StatusCode.InvalidMessageFormat);
            }
            // content length
            int contentLength = _reader.ReadInt32();
            // request uri
            string requestUri = _reader.ReadString();

            if (!CheckRequestUri(requestUri))
            {
                BinaryWireProtocol.ThrowException(BinaryWireProtocol.StatusCode.InvalidRequestUri);
            }
            // request headers
            requestHeaders = ReadHeaders();
            // set special headers
            requestHeaders[BinaryWireProtocol.WellKnownHeaders.ConnectionId] = _connectionId;
            requestHeaders[BinaryWireProtocol.WellKnownHeaders.RequestUri]   = requestUri;

            // create stream for request reading
            if (contentLength == -1)
            {
                requestStream = new ChunkedReadStream(_bufferedStream);
            }
            else
            {
                requestStream = new FixedReadStream(_bufferedStream, contentLength);
            }

            // set client principal
            RemotingService.ClientPrincipal = _transport.ClientPrincipal;
        }
예제 #3
0
        /// <summary>
        /// Reads transport headers
        /// </summary>
        private ITransportHeaders ReadHeaders()
        {
            TransportHeaders headers = new TransportHeaders();

            // for error-header procesing
            bool   errorHeader  = false;
            string errorMessage = null;
            byte   statusCode   = BinaryWireProtocol.StatusCode.InternalError;

            // proceed headers
            string headerName   = null;
            bool   endOfHeaders = false;

            while (!endOfHeaders)
            {
                // read header type
                byte headerType = _reader.ReadByte();

                switch (headerType)
                {
                case BinaryWireProtocol.HeaderType.EndOfHeaders:
                    // end-of-headers marker
                    endOfHeaders = true;
                    continue;

                case BinaryWireProtocol.HeaderType.ErrorMessage:
                    // error header
                    errorHeader  = true;
                    errorMessage = _reader.ReadString();
                    continue;

                case BinaryWireProtocol.HeaderType.StatusCode:
                    // status code
                    statusCode = _reader.ReadByte();
                    continue;

                case BinaryWireProtocol.HeaderType.Custom:
                    // custom header
                    headerName = _reader.ReadString();
                    break;

                default:
                    // well-known header
                    headerName = BinaryWireProtocol.GetWellKnownHeader(headerType);
                    break;
                }

                if (headerName == null)
                {
                    BinaryWireProtocol.ThrowException(BinaryWireProtocol.StatusCode.InvalidMessageFormat);
                }

                // read header value
                headers[headerName] = _reader.ReadString();
            }

            if (errorHeader)
            {
                BinaryWireProtocol.ThrowException(statusCode, "Internal server error: " + errorMessage);
            }

            return(headers);
        }