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);
            }
예제 #2
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;
            }
 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;
 }