Example #1
0
        public override Message ReadMessage(ArraySegment <byte> buffer, BufferManager bufferManager, string contentType)
        {
            if (bufferManager == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bufferManager");
            }
            if (contentType == this.ContentType)
            {
                contentType = null;
            }
            MtomBufferedMessageData messageData = this.TakeBufferedReader();

            messageData.ContentType = contentType;
            messageData.Open(buffer, bufferManager);
            RecycledMessageState recycledMessageState = messageData.TakeMessageState();

            if (recycledMessageState == null)
            {
                recycledMessageState = new RecycledMessageState();
            }
            Message message = new BufferedMessage(messageData, recycledMessageState)
            {
                Properties = { Encoder = this }
            };

            if (MessageLogger.LogMessagesAtTransportLevel)
            {
                MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportReceive);
            }
            return(message);
        }
Example #2
0
            public override Message ReadMessage(ArraySegment <byte> buffer, BufferManager bufferManager, string contentType)
            {
                if (bufferManager == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("bufferManager"));
                }
                UTF8BufferedMessageData messageData = this.TakeBufferedReader();

                messageData.Encoding = TextMessageEncoderFactory.GetEncodingFromContentType(contentType, this.contentEncodingMap);
                messageData.Open(buffer, bufferManager);
                RecycledMessageState recycledMessageState = messageData.TakeMessageState();

                if (recycledMessageState == null)
                {
                    recycledMessageState = new RecycledMessageState();
                }
                Message message = new BufferedMessage(messageData, recycledMessageState)
                {
                    Properties = { Encoder = this }
                };

                if (MessageLogger.LogMessagesAtTransportLevel)
                {
                    MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportReceive);
                }
                return(message);
            }
 public RecycledMessageState DoTakeMessageState()
 {
     RecycledMessageState messageState = this.messageState;
     if (messageState != null)
     {
         this.messageState = null;
         return messageState;
     }
     return this.messageStatePool.Take();
 }
            public override Message ReadMessage(ArraySegment <byte> buffer, BufferManager bufferManager, string contentType)
            {
                Message message;

                if (bufferManager == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bufferManager");
                }
                if (((contentType != null) && (contentType != this.ContentType)) && !contentType.StartsWith(this.ContentType, StringComparison.OrdinalIgnoreCase))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("EncoderUnrecognizedContentType", new object[] { contentType, this.ContentType })));
                }
                if (this.isSession)
                {
                    if (this.readerSession == null)
                    {
                        this.readerSession   = new XmlBinaryReaderSession();
                        this.messagePatterns = new MessagePatterns(this.factory.binaryVersion.Dictionary, this.readerSession, this.MessageVersion);
                    }
                    try
                    {
                        buffer = this.ExtractSessionInformationFromMessage(buffer);
                    }
                    catch (InvalidDataException)
                    {
                        MessageLogger.LogMessage(buffer, MessageLoggingSource.Malformed);
                        throw;
                    }
                }
                BinaryMessageEncoderFactory.BinaryBufferedMessageData messageData = this.factory.TakeBufferedData(this);
                if (this.messagePatterns != null)
                {
                    message = this.messagePatterns.TryCreateMessage(buffer.Array, buffer.Offset, buffer.Count, bufferManager, messageData);
                }
                else
                {
                    message = null;
                }
                if (message == null)
                {
                    messageData.Open(buffer, bufferManager);
                    RecycledMessageState recycledMessageState = messageData.TakeMessageState();
                    if (recycledMessageState == null)
                    {
                        recycledMessageState = new RecycledMessageState();
                    }
                    message = new BufferedMessage(messageData, recycledMessageState);
                }
                message.Properties.Encoder = this;
                if (MessageLogger.LogMessagesAtTransportLevel)
                {
                    MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportReceive);
                }
                return(message);
            }
        public RecycledMessageState DoTakeMessageState()
        {
            RecycledMessageState messageState = this.messageState;

            if (messageState != null)
            {
                this.messageState = null;
                return(messageState);
            }
            return(this.messageStatePool.Take());
        }
 public void DoReturnMessageState(RecycledMessageState messageState)
 {
     if (_messageState == null)
     {
         _messageState = messageState;
     }
     else
     {
         _messageStatePool.Return(messageState);
     }
 }
Example #7
0
 public void DoReturnMessageState(RecycledMessageState messageState)
 {
     if (_messageState == null)
     {
         _messageState = messageState;
     }
     else
     {
         _messageStatePool.Return(messageState);
     }
 }
 public void ReturnMessageState(RecycledMessageState messageState)
 {
     if (this.multipleUsers)
     {
         lock (this.ThisLock)
         {
             this.DoReturnMessageState(messageState);
             return;
         }
     }
     this.DoReturnMessageState(messageState);
 }
Example #9
0
 public void ReturnMessageState(RecycledMessageState messageState)
 {
     if (_multipleUsers)
     {
         lock (ThisLock)
         {
             DoReturnMessageState(messageState);
         }
     }
     else
     {
         DoReturnMessageState(messageState);
     }
 }
Example #10
0
        public RecycledMessageState DoTakeMessageState()
        {
            RecycledMessageState messageState = _messageState;

            if (messageState != null)
            {
                _messageState = null;
                return(messageState);
            }
            else
            {
                return(_messageStatePool.Take());
            }
        }
Example #11
0
        public override Message ReadMessage(ArraySegment <byte> buffer, BufferManager bufferManager, string contentType)
        {
            if (bufferManager == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bufferManager");
            }

            if (contentType == this.ContentType)
            {
                contentType = null;
            }

            if (TD.MtomMessageDecodingStartIsEnabled())
            {
                TD.MtomMessageDecodingStart();
            }

            MtomBufferedMessageData messageData = TakeBufferedReader();

            messageData.ContentType = contentType;
            messageData.Open(buffer, bufferManager);
            RecycledMessageState messageState = messageData.TakeMessageState();

            if (messageState == null)
            {
                messageState = new RecycledMessageState();
            }
            Message message = new BufferedMessage(messageData, messageState);

            message.Properties.Encoder = this;
            if (MessageLogger.LogMessagesAtTransportLevel)
            {
                MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportReceive);
            }

            if (TD.MessageReadByEncoderIsEnabled() && buffer != null)
            {
                TD.MessageReadByEncoder(
                    EventTraceActivityHelper.TryExtractActivity(message, true),
                    buffer.Count,
                    this);
            }

            return(message);
        }
 public override void Close()
 {
     lock (this.thisLock)
     {
         if (!this.closed)
         {
             this.closed = true;
             this.recycledMessageState.ReturnHeaders(this.headers);
             this.messageDataAtBody.ReturnMessageState(this.recycledMessageState);
             this.messageDataAtBody.Close();
             this.recycledMessageState = null;
             this.messageDataAtBody    = null;
             this.properties           = null;
             this.messageVersion       = null;
             this.headers = null;
         }
     }
 }
 public PatternMessageBuffer(IBufferedMessageData messageDataAtBody, MessageVersion messageVersion, KeyValuePair <string, object>[] properties, MessageHeaders headers)
 {
     this.messageDataAtBody = messageDataAtBody;
     this.messageDataAtBody.Open();
     this.recycledMessageState = this.messageDataAtBody.TakeMessageState();
     if (this.recycledMessageState == null)
     {
         this.recycledMessageState = new RecycledMessageState();
     }
     this.headers = this.recycledMessageState.TakeHeaders();
     if (this.headers == null)
     {
         this.headers = new MessageHeaders(messageVersion);
     }
     this.headers.CopyHeadersFrom(headers);
     this.properties     = properties;
     this.messageVersion = messageVersion;
 }
Example #14
0
            public override Message ReadMessage(ArraySegment <byte> buffer, BufferManager bufferManager, string contentType)
            {
                if (bufferManager == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(bufferManager)));
                }

                if (WcfEventSource.Instance.TextMessageDecodingStartIsEnabled())
                {
                    WcfEventSource.Instance.TextMessageDecodingStart();
                }

                Message message;

                UTF8BufferedMessageData messageData = TakeBufferedReader();

                messageData.Encoding = GetEncodingFromContentType(contentType, _contentEncodingMap);
                messageData.Open(buffer, bufferManager);
                RecycledMessageState messageState = messageData.TakeMessageState();

                if (messageState == null)
                {
                    messageState = new RecycledMessageState();
                }

                message = new BufferedMessage(messageData, messageState);

                message.Properties.Encoder = this;

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

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

                return(message);
            }
 public override Message CreateMessage()
 {
     lock (this.ThisLock)
     {
         if (this.closed)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(base.CreateBufferDisposedException());
         }
         RecycledMessageState recycledMessageState = this.messageData.TakeMessageState();
         if (recycledMessageState == null)
         {
             recycledMessageState = new RecycledMessageState();
         }
         BufferedMessage message = new BufferedMessage(this.messageData, recycledMessageState, this.understoodHeaders, this.understoodHeadersModified);
         message.Properties.CopyProperties(this.properties);
         this.messageData.Open();
         return message;
     }
 }
 public override Message CreateMessage()
 {
     lock (this.ThisLock)
     {
         if (this.closed)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(base.CreateBufferDisposedException());
         }
         RecycledMessageState recycledMessageState = this.messageData.TakeMessageState();
         if (recycledMessageState == null)
         {
             recycledMessageState = new RecycledMessageState();
         }
         BufferedMessage message = new BufferedMessage(this.messageData, recycledMessageState, this.understoodHeaders, this.understoodHeadersModified);
         message.Properties.CopyProperties(this.properties);
         this.messageData.Open();
         return(message);
     }
 }
Example #17
0
 public override Message CreateMessage()
 {
     lock (ThisLock)
     {
         if (_closed)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateBufferDisposedException());
         }
         RecycledMessageState recycledMessageState = _messageData.TakeMessageState();
         if (recycledMessageState == null)
         {
             recycledMessageState = new RecycledMessageState();
         }
         BufferedMessage bufferedMessage = new BufferedMessage(_messageData, recycledMessageState, _understoodHeaders, _understoodHeadersModified);
         bufferedMessage.Properties.CopyProperties(_properties);
         _messageData.Open();
         return(bufferedMessage);
     }
 }
 public override void Close()
 {
     lock (this.thisLock)
     {
         if (!this.closed)
         {
             this.closed = true;
             this.recycledMessageState.ReturnHeaders(this.headers);
             this.messageDataAtBody.ReturnMessageState(this.recycledMessageState);
             this.messageDataAtBody.Close();
             this.recycledMessageState = null;
             this.messageDataAtBody = null;
             this.properties = null;
             this.messageVersion = null;
             this.headers = null;
         }
     }
 }
 public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
 {
     Message message;
     if (bufferManager == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bufferManager");
     }
     if (((contentType != null) && (contentType != this.ContentType)) && !contentType.StartsWith(this.ContentType, StringComparison.OrdinalIgnoreCase))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("EncoderUnrecognizedContentType", new object[] { contentType, this.ContentType })));
     }
     if (this.isSession)
     {
         if (this.readerSession == null)
         {
             this.readerSession = new XmlBinaryReaderSession();
             this.messagePatterns = new MessagePatterns(this.factory.binaryVersion.Dictionary, this.readerSession, this.MessageVersion);
         }
         try
         {
             buffer = this.ExtractSessionInformationFromMessage(buffer);
         }
         catch (InvalidDataException)
         {
             MessageLogger.LogMessage(buffer, MessageLoggingSource.Malformed);
             throw;
         }
     }
     BinaryMessageEncoderFactory.BinaryBufferedMessageData messageData = this.factory.TakeBufferedData(this);
     if (this.messagePatterns != null)
     {
         message = this.messagePatterns.TryCreateMessage(buffer.Array, buffer.Offset, buffer.Count, bufferManager, messageData);
     }
     else
     {
         message = null;
     }
     if (message == null)
     {
         messageData.Open(buffer, bufferManager);
         RecycledMessageState recycledMessageState = messageData.TakeMessageState();
         if (recycledMessageState == null)
         {
             recycledMessageState = new RecycledMessageState();
         }
         message = new BufferedMessage(messageData, recycledMessageState);
     }
     message.Properties.Encoder = this;
     if (MessageLogger.LogMessagesAtTransportLevel)
     {
         MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportReceive);
     }
     return message;
 }
 public void ReturnMessageState(RecycledMessageState messageState)
 {
     if (this.multipleUsers)
     {
         lock (this.ThisLock)
         {
             this.DoReturnMessageState(messageState);
             return;
         }
     }
     this.DoReturnMessageState(messageState);
 }
Example #21
0
            public PatternMessage(IBufferedMessageData messageData, MessageVersion messageVersion,
                KeyValuePair<string, object>[] properties, MessageHeaders headers)
            {
                _messageData = messageData;
                _messageData.Open();
                _recycledMessageState = _messageData.TakeMessageState();
                if (_recycledMessageState == null)
                {
                    _recycledMessageState = new RecycledMessageState();
                }

                _properties = _recycledMessageState.TakeProperties();
                if (_properties == null)
                {
                    _properties = new MessageProperties();
                }
                if (properties != null)
                {
                    _properties.CopyProperties(properties);
                }

                _headers = _recycledMessageState.TakeHeaders();
                if (_headers == null)
                {
                    _headers = new MessageHeaders(messageVersion);
                }
                if (headers != null)
                {
                    _headers.CopyHeadersFrom(headers);
                }

                XmlDictionaryReader reader = messageData.GetMessageReader();
                reader.ReadStartElement();
                VerifyStartBody(reader, messageVersion.Envelope);
                ReadStartBody(reader);
                _reader = reader;
            }
Example #22
0
            public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
            {
                if (bufferManager == null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bufferManager");
                }

                CompressionFormat compressionFormat = this.CheckContentType(contentType);

                if (WcfEventSource.Instance.BinaryMessageDecodingStartIsEnabled())
                {
                    WcfEventSource.Instance.BinaryMessageDecodingStart();
                }

                if (compressionFormat != CompressionFormat.None)
                {
                    MessageEncoderCompressionHandler.DecompressBuffer(ref buffer, bufferManager, compressionFormat, _maxReceivedMessageSize);
                }

                if (_isSession)
                {
                    if (_readerSession == null)
                    {
                        _readerSession = new XmlBinaryReaderSession();
                        _messagePatterns = new MessagePatterns(_factory._binaryVersion.Dictionary, _readerSession, this.MessageVersion);
                    }
                    try
                    {
                        buffer = ExtractSessionInformationFromMessage(buffer);
                    }
                    catch (InvalidDataException)
                    {
                        MessageLogger.LogMessage(buffer, MessageLoggingSource.Malformed);
                        throw;
                    }
                }
                BinaryBufferedMessageData messageData = _factory.TakeBufferedData(this);
                Message message;
                if (_messagePatterns != null)
                {
                    message = _messagePatterns.TryCreateMessage(buffer.Array, buffer.Offset, buffer.Count, bufferManager, messageData);
                }
                else
                {
                    message = null;
                }
                if (message == null)
                {
                    messageData.Open(buffer, bufferManager);
                    RecycledMessageState messageState = messageData.TakeMessageState();
                    if (messageState == null)
                    {
                        messageState = new RecycledMessageState();
                    }
                    message = new BufferedMessage(messageData, messageState);
                }
                message.Properties.Encoder = this;

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

                return message;
            }
Example #23
0
 public override void Close()
 {
     lock (_thisLock)
     {
         if (!_closed)
         {
             _closed = true;
             _recycledMessageState.ReturnHeaders(_headers);
             _messageDataAtBody.ReturnMessageState(_recycledMessageState);
             _messageDataAtBody.Close();
             _recycledMessageState = null;
             _messageDataAtBody = null;
             _properties = null;
             _messageVersion = null;
             _headers = null;
         }
     }
 }
Example #24
0
            public PatternMessageBuffer(IBufferedMessageData messageDataAtBody, MessageVersion messageVersion,
                KeyValuePair<string, object>[] properties, MessageHeaders headers)
            {
                _messageDataAtBody = messageDataAtBody;
                _messageDataAtBody.Open();

                _recycledMessageState = _messageDataAtBody.TakeMessageState();
                if (_recycledMessageState == null)
                {
                    _recycledMessageState = new RecycledMessageState();
                }

                _headers = _recycledMessageState.TakeHeaders();
                if (_headers == null)
                {
                    _headers = new MessageHeaders(messageVersion);
                }
                _headers.CopyHeadersFrom(headers);
                _properties = properties;
                _messageVersion = messageVersion;
            }
Example #25
0
            protected override void OnClose()
            {
                Exception ex = null;
                try
                {
                    base.OnClose();
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    ex = e;
                }

                try
                {
                    _properties.Dispose();
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    if (ex == null)
                    {
                        ex = e;
                    }
                }

                try
                {
                    if (_reader != null)
                    {
                        _reader.Dispose();
                    }
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    if (ex == null)
                    {
                        ex = e;
                    }
                }

                try
                {
                    _recycledMessageState.ReturnHeaders(_headers);
                    _recycledMessageState.ReturnProperties(_properties);
                    _messageData.ReturnMessageState(_recycledMessageState);
                    _recycledMessageState = null;
                    _messageData.Close();
                    _messageData = null;
                }
                catch (Exception e)
                {
                    if (Fx.IsFatal(e))
                    {
                        throw;
                    }
                    if (ex == null)
                    {
                        ex = e;
                    }
                }

                if (ex != null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(ex);
                }
            }
 public void ReturnMessageState(RecycledMessageState messageState)
 {
     if (_multipleUsers)
     {
         lock (ThisLock)
         {
             DoReturnMessageState(messageState);
         }
     }
     else
     {
         DoReturnMessageState(messageState);
     }
 }
Example #27
0
            public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
            {
                if (bufferManager == null)
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException("bufferManager"));

                if (TD.TextMessageDecodingStartIsEnabled())
                {
                    TD.TextMessageDecodingStart();
                }

                Message message;

                UTF8BufferedMessageData messageData = TakeBufferedReader();
                messageData.Encoding = GetEncodingFromContentType(contentType, this.contentEncodingMap);
                messageData.Open(buffer, bufferManager);
                RecycledMessageState messageState = messageData.TakeMessageState();
                if (messageState == null)
                    messageState = new RecycledMessageState();
                message = new BufferedMessage(messageData, messageState);

                message.Properties.Encoder = this;

                if (TD.MessageReadByEncoderIsEnabled() && buffer != null)
                {
                    TD.MessageReadByEncoder(
                        EventTraceActivityHelper.TryExtractActivity(message, true),
                        buffer.Count,
                        this);
                }

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

                return message;
            }
 public RecycledMessageState DoTakeMessageState()
 {
     RecycledMessageState messageState = _messageState;
     if (messageState != null)
     {
         _messageState = null;
         return messageState;
     }
     else
     {
         return _messageStatePool.Take();
     }
 }
Example #29
0
 public override Message CreateMessage()
 {
     lock (ThisLock)
     {
         if (_closed)
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateBufferDisposedException());
         RecycledMessageState recycledMessageState = _messageData.TakeMessageState();
         if (recycledMessageState == null)
             recycledMessageState = new RecycledMessageState();
         BufferedMessage bufferedMessage = new BufferedMessage(_messageData, recycledMessageState, _understoodHeaders, _understoodHeadersModified);
         bufferedMessage.Properties.CopyProperties(_properties);
         _messageData.Open();
         return bufferedMessage;
     }
 }
Example #30
0
 public PatternMessage(IBufferedMessageData messageData, MessageVersion messageVersion)
 {
     _messageData = messageData;
     _recycledMessageState = messageData.TakeMessageState();
     if (_recycledMessageState == null)
     {
         _recycledMessageState = new RecycledMessageState();
     }
     _properties = _recycledMessageState.TakeProperties();
     if (_properties == null)
     {
         _properties = new MessageProperties();
     }
     _headers = _recycledMessageState.TakeHeaders();
     if (_headers == null)
     {
         _headers = new MessageHeaders(messageVersion);
     }
     else
     {
         _headers.Init(messageVersion);
     }
     XmlDictionaryReader reader = messageData.GetMessageReader();
     reader.ReadStartElement();
     VerifyStartBody(reader, messageVersion.Envelope);
     ReadStartBody(reader);
     _reader = reader;
 }
 public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
 {
     if (bufferManager == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("bufferManager");
     }
     if (contentType == this.ContentType)
     {
         contentType = null;
     }
     MtomBufferedMessageData messageData = this.TakeBufferedReader();
     messageData.ContentType = contentType;
     messageData.Open(buffer, bufferManager);
     RecycledMessageState recycledMessageState = messageData.TakeMessageState();
     if (recycledMessageState == null)
     {
         recycledMessageState = new RecycledMessageState();
     }
     Message message = new BufferedMessage(messageData, recycledMessageState) {
         Properties = { Encoder = this }
     };
     if (MessageLogger.LogMessagesAtTransportLevel)
     {
         MessageLogger.LogMessage(ref message, MessageLoggingSource.TransportReceive);
     }
     return message;
 }