public StreamedMessage(XmlDictionaryReader reader, int maxSizeOfHeaders, MessageVersion desiredVersion)
 {
     if (reader.NodeType != XmlNodeType.Element)
     {
         reader.MoveToContent();
     }
     if (desiredVersion.Envelope == EnvelopeVersion.None)
     {
         this.reader           = reader;
         this.headerAttributes = XmlAttributeHolder.emptyArray;
         this.headers          = new MessageHeaders(desiredVersion);
     }
     else
     {
         this.envelopeAttributes = XmlAttributeHolder.ReadAttributes(reader, ref maxSizeOfHeaders);
         this.envelopePrefix     = reader.Prefix;
         EnvelopeVersion envelopeVersion = ReceivedMessage.ReadStartEnvelope(reader);
         if (desiredVersion.Envelope != envelopeVersion)
         {
             Exception innerException = new ArgumentException(System.ServiceModel.SR.GetString("EncoderEnvelopeVersionMismatch", new object[] { envelopeVersion, desiredVersion.Envelope }), "reader");
             throw TraceUtility.ThrowHelperError(new CommunicationException(innerException.Message, innerException), this);
         }
         if (ReceivedMessage.HasHeaderElement(reader, envelopeVersion))
         {
             this.headerPrefix     = reader.Prefix;
             this.headerAttributes = XmlAttributeHolder.ReadAttributes(reader, ref maxSizeOfHeaders);
             this.headers          = new MessageHeaders(desiredVersion, reader, this.envelopeAttributes, this.headerAttributes, ref maxSizeOfHeaders);
         }
         else
         {
             this.headerAttributes = XmlAttributeHolder.emptyArray;
             this.headers          = new MessageHeaders(desiredVersion);
         }
         if (reader.NodeType != XmlNodeType.Element)
         {
             reader.MoveToContent();
         }
         this.bodyPrefix = reader.Prefix;
         ReceivedMessage.VerifyStartBody(reader, envelopeVersion);
         this.bodyAttributes = XmlAttributeHolder.ReadAttributes(reader, ref maxSizeOfHeaders);
         if (base.ReadStartBody(reader))
         {
             this.reader = reader;
         }
         else
         {
             this.quotas = new XmlDictionaryReaderQuotas();
             reader.Quotas.CopyTo(this.quotas);
             reader.Close();
         }
     }
 }
Beispiel #2
0
        public BufferedMessage(IBufferedMessageData messageData, System.ServiceModel.Channels.RecycledMessageState recycledMessageState, bool[] understoodHeaders, bool understoodHeadersModified)
        {
            bool flag = true;

            try
            {
                this.recycledMessageState = recycledMessageState;
                this.messageData          = messageData;
                this.properties           = recycledMessageState.TakeProperties();
                if (this.properties == null)
                {
                    this.properties = new MessageProperties();
                }
                XmlDictionaryReader messageReader  = messageData.GetMessageReader();
                MessageVersion      messageVersion = messageData.MessageEncoder.MessageVersion;
                if (messageVersion.Envelope == EnvelopeVersion.None)
                {
                    this.reader  = messageReader;
                    this.headers = new MessageHeaders(messageVersion);
                }
                else
                {
                    EnvelopeVersion envelopeVersion = ReceivedMessage.ReadStartEnvelope(messageReader);
                    if (messageVersion.Envelope != envelopeVersion)
                    {
                        Exception innerException = new ArgumentException(System.ServiceModel.SR.GetString("EncoderEnvelopeVersionMismatch", new object[] { envelopeVersion, messageVersion.Envelope }), "reader");
                        throw TraceUtility.ThrowHelperError(new CommunicationException(innerException.Message, innerException), this);
                    }
                    if (ReceivedMessage.HasHeaderElement(messageReader, envelopeVersion))
                    {
                        this.headers = recycledMessageState.TakeHeaders();
                        if (this.headers == null)
                        {
                            this.headers = new MessageHeaders(messageVersion, messageReader, messageData, recycledMessageState, understoodHeaders, understoodHeadersModified);
                        }
                        else
                        {
                            this.headers.Init(messageVersion, messageReader, messageData, recycledMessageState, understoodHeaders, understoodHeadersModified);
                        }
                    }
                    else
                    {
                        this.headers = new MessageHeaders(messageVersion);
                    }
                    ReceivedMessage.VerifyStartBody(messageReader, envelopeVersion);
                    int maxSizeOfHeaders = 0x7fffffff;
                    this.bodyAttributes = XmlAttributeHolder.ReadAttributes(messageReader, ref maxSizeOfHeaders);
                    if (maxSizeOfHeaders < 0x7fffefff)
                    {
                        this.bodyAttributes = null;
                    }
                    if (base.ReadStartBody(messageReader))
                    {
                        this.reader = messageReader;
                    }
                    else
                    {
                        messageReader.Close();
                    }
                }
                flag = false;
            }
            finally
            {
                if (flag && MessageLogger.LoggingEnabled)
                {
                    MessageLogger.LogMessage(messageData.Buffer, MessageLoggingSource.Malformed);
                }
            }
        }