Exemplo n.º 1
0
        public override Message ReadMessage(Stream stream, int maxSizeOfHeaders, string contentType)
        {
            if (stream == null)
            {
                throw FxTrace.Exception.ArgumentNull("stream");
            }

            if (TD.ByteStreamMessageDecodingStartIsEnabled())
            {
                TD.ByteStreamMessageDecodingStart();
            }

            Message message = ByteStreamMessage.CreateMessage(stream, this.quotas, this.moveBodyReaderToContent);

            message.Properties.Encoder = this;

            if (SMTD.StreamedMessageReadByEncoderIsEnabled())
            {
                SMTD.StreamedMessageReadByEncoder(EventTraceActivityHelper.TryExtractActivity(message, true));
            }

            if (MessageLogger.LogMessagesAtTransportLevel)
            {
                MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportReceive);
            }

            return(message);
        }
        /// <summary>
        /// An extension method for getting a <see cref="Message"/> instance
        /// from an <see cref="HttpRequestMessage"/> instance.
        /// </summary>
        /// <remarks>
        /// The <see cref="Message"/> instance can be read, written and copied
        /// just as a traditional <see cref="ByteStreamMessage"/> instance. The
        /// <see cref="Message"/> instance can also "read" to retrieve the original
        /// <see cref="HttpRequestMessage"/> instance by calling the
        /// <see cref="MessageExtensionMethods.ToHttpRequestMessage">
        /// Message.ToHttpRequestMessage()</see> extension method.
        /// </remarks>
        /// <param name="httpRequestMessage">The <see cref="HttpRequestMessage"/>
        /// from which to create the <see cref="Message"/> instance.</param>
        /// <returns>The new <see cref="Message"/> instance.</returns>
        public static Message ToMessage(this HttpRequestMessage httpRequestMessage)
        {
            if (httpRequestMessage == null)
            {
                throw FxTrace.Exception.ArgumentNull("httpRequestMessage");
            }

            Message message = ByteStreamMessage.CreateMessage(httpRequestMessage, null);

            message.ConfigureAsHttpMessage(httpRequestMessage);

            return(message);
        }
Exemplo n.º 3
0
        public Stream GetResponseMessageStream(Message message)
        {
            if (message == null)
            {
                throw FxTrace.Exception.ArgumentNull("message");
            }

            ThrowIfMismatchedMessageVersion(message);

            if (!ByteStreamMessage.IsInternalByteStreamMessage(message))
            {
                return(null);
            }

            return(message.GetBody <Stream>());
        }
Exemplo n.º 4
0
        public override Message ReadMessage(ArraySegment <byte> buffer, BufferManager bufferManager, string contentType)
        {
            if (buffer.Array == null)
            {
                throw FxTrace.Exception.ArgumentNull("buffer.Array");
            }

            if (bufferManager == null)
            {
                throw FxTrace.Exception.ArgumentNull("bufferManager");
            }

            if (TD.ByteStreamMessageDecodingStartIsEnabled())
            {
                TD.ByteStreamMessageDecodingStart();
            }

            ByteStreamBufferedMessageData messageData = new ByteStreamBufferedMessageData(buffer, bufferManager);

            Message message = ByteStreamMessage.CreateMessage(messageData, this.bufferedReadReaderQuotas, this.moveBodyReaderToContent);

            message.Properties.Encoder = this;

            if (SMTD.MessageReadByEncoderIsEnabled())
            {
                SMTD.MessageReadByEncoder(
                    EventTraceActivityHelper.TryExtractActivity(message, true),
                    buffer.Count,
                    this);
            }

            if (MessageLogger.LogMessagesAtTransportLevel)
            {
                MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportReceive);
            }

            return(message);
        }