internal void WriteTo(XmlWriter writer, Func <string, string, bool> shouldSkipElement)
        {
            if (_buffer != null)
            {
                using (XmlDictionaryReader reader = _buffer.GetReader(0))
                {
                    reader.ReadStartElement();
                    while (reader.IsStartElement())
                    {
                        if (shouldSkipElement != null && shouldSkipElement(reader.LocalName, reader.NamespaceURI))
                        {
                            reader.Skip();
                            continue;
                        }

                        writer.WriteNode(reader, false);
                    }
                }
            }
            else
            {
                for (int i = 0; i < Items.Count; ++i)
                {
                    Items[i].WriteTo(writer);
                }
            }
        }
示例#2
0
        protected override void OnWriteDetail(XmlDictionaryWriter writer, EnvelopeVersion version)
        {
            using (XmlReader r = _detail.GetReader(0))
            {
                // Start the element
                base.OnWriteStartDetail(writer, version);

                // Copy the attributes
                while (r.MoveToNextAttribute())
                {
                    if (ShouldWriteDetailAttribute(version, r.Prefix, r.LocalName, r.Value))
                    {
                        writer.WriteAttributeString(r.Prefix, r.LocalName, r.NamespaceURI, r.Value);
                    }
                }
                r.MoveToElement();

                r.Read();

                // Copy the contents
                while (r.NodeType != XmlNodeType.EndElement)
                {
                    writer.WriteNode(r, false);
                }

                // End the element
                writer.WriteEndElement();
            }
        }
 private XmlDictionaryReader CreateFullBodyReaderFromBufferedState()
 {
     if (_messageBuffer != null)
     {
         XmlDictionaryReader reader = _messageBuffer.GetReader(0);
         MoveToBody(reader);
         return(reader);
     }
     else
     {
         return(((BufferedMessage)InnerMessage).GetBufferedReaderAtBody());
     }
 }
 public SecurityVerifiedMessage(Message messageToProcess, ReceiveSecurityHeader securityHeader)
     : base(messageToProcess)
 {
     ReceivedSecurityHeader = securityHeader;
     if (securityHeader.RequireMessageProtection)
     {
         XmlDictionaryReader messageReader;
         BufferedMessage     bufferedMessage = InnerMessage as BufferedMessage;
         if (bufferedMessage != null && Headers.ContainsOnlyBufferedMessageHeaders)
         {
             messageReader = bufferedMessage.GetMessageReader();
         }
         else
         {
             _messageBuffer = new XmlBuffer(int.MaxValue);
             XmlDictionaryWriter writer = _messageBuffer.OpenSection(ReceivedSecurityHeader.ReaderQuotas);
             InnerMessage.WriteMessage(writer);
             _messageBuffer.CloseSection();
             _messageBuffer.Close();
             messageReader = _messageBuffer.GetReader(0);
         }
         MoveToSecurityHeader(messageReader, securityHeader.HeaderIndex, true);
         _cachedReaderAtSecurityHeader = messageReader;
         _state = BodyState.Buffered;
     }
     else
     {
         _envelopeAttributes = XmlAttributeHolder.emptyArray;
         _headerAttributes   = XmlAttributeHolder.emptyArray;
         _bodyAttributes     = XmlAttributeHolder.emptyArray;
         _canDelegateCreateBufferedCopyToInnerMessage = true;
     }
 }
示例#5
0
        protected virtual XmlDictionaryReader OnGetReaderAtBodyContents()
        {
            XmlBuffer           buffer = new XmlBuffer(0x7fffffff);
            XmlDictionaryWriter writer = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            if (this.Version.Envelope != EnvelopeVersion.None)
            {
                this.OnWriteStartEnvelope(writer);
                this.OnWriteStartBody(writer);
            }
            this.OnWriteBodyContents(writer);
            if (this.Version.Envelope != EnvelopeVersion.None)
            {
                writer.WriteEndElement();
                writer.WriteEndElement();
            }
            buffer.CloseSection();
            buffer.Close();
            XmlDictionaryReader reader = buffer.GetReader(0);

            if (this.Version.Envelope != EnvelopeVersion.None)
            {
                reader.ReadStartElement();
                reader.ReadStartElement();
            }
            reader.MoveToContent();
            return(reader);
        }
        public XmlReader GetReaderAtElementExtensions()
        {
            XmlBuffer extensionsBuffer = GetOrCreateBufferOverExtensions();
            XmlReader reader           = extensionsBuffer.GetReader(0);

            reader.ReadStartElement();
            return(reader);
        }
        public async Task <XmlReader> GetReaderAtElementExtensionsAsync()
        {
            XmlBuffer extensionsBuffer = await GetOrCreateBufferOverExtensions();

            XmlReader reader = extensionsBuffer.GetReader(0);

            reader.ReadStartElement();
            return(reader);
        }
示例#8
0
        public virtual XmlDictionaryReader GetAddressHeaderReader()
        {
            XmlBuffer           buffer = new XmlBuffer(int.MaxValue);
            XmlDictionaryWriter writer = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            WriteAddressHeader(writer);
            buffer.CloseSection();
            buffer.Close();
            return(buffer.GetReader(0));
        }
 internal async Task WriteToAsync(XmlWriter writer)
 {
     if (_buffer != null)
     {
         using (XmlDictionaryReader reader = _buffer.GetReader(0))
         {
             reader.ReadStartElement();
             while (reader.IsStartElement())
             {
                 await writer.WriteNodeAsync(reader, false);
             }
         }
     }
     else
     {
         for (int i = 0; i < Items.Count; ++i)
         {
             await Items[i].WriteToAsync(writer);
         }
     }
 }
        private XmlDictionaryReader GetComparableReader()
        {
            XmlBuffer           buffer = new XmlBuffer(0x7fffffff);
            XmlDictionaryWriter writer = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            ParameterHeader.WriteStartHeader(writer, this, AddressingVersion.WSAddressingAugust2004);
            ParameterHeader.WriteHeaderContents(writer, this);
            writer.WriteEndElement();
            buffer.CloseSection();
            buffer.Close();
            return(buffer.GetReader(0));
        }
 internal void WriteTo(XmlWriter writer)
 {
     if (_buffer != null)
     {
         using (XmlDictionaryReader reader = _buffer.GetReader(0))
         {
             reader.ReadStartElement();
             while (reader.IsStartElement())
             {
                 writer.WriteNode(reader, false);
             }
         }
     }
     else
     {
         for (int i = 0; i < this.Items.Count; ++i)
         {
             this.Items[i].WriteTo(writer);
         }
     }
 }
示例#12
0
        protected virtual XmlDictionaryReader OnGetReaderAtDetailContents()
        {
            XmlBuffer           detailBuffer = new XmlBuffer(int.MaxValue);
            XmlDictionaryWriter writer       = detailBuffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            OnWriteDetail(writer, EnvelopeVersion.Soap12);  // Wrap in soap 1.2 by default
            detailBuffer.CloseSection();
            detailBuffer.Close();
            XmlDictionaryReader reader = detailBuffer.GetReader(0);

            reader.Read(); // Skip the detail element
            return(reader);
        }
        protected virtual XmlDictionaryReader OnGetReaderAtDetailContents()
        {
            XmlBuffer           buffer = new XmlBuffer(0x7fffffff);
            XmlDictionaryWriter writer = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            this.OnWriteDetail(writer, EnvelopeVersion.Soap12);
            buffer.CloseSection();
            buffer.Close();
            XmlDictionaryReader reader = buffer.GetReader(0);

            reader.Read();
            return(reader);
        }
示例#14
0
            protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
            {
                XmlDictionaryReader reader = _buffer.GetReader(0);

                using (reader)
                {
                    reader.ReadStartElement();
                    while (reader.NodeType != XmlNodeType.EndElement)
                    {
                        writer.WriteNode(reader, false);
                    }
                    reader.ReadEndElement();
                }
            }
示例#15
0
        XmlDictionaryReader GetComparableReader()
        {
            XmlBuffer           buffer = new XmlBuffer(int.MaxValue);
            XmlDictionaryWriter writer = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            // WSAddressingAugust2004 does not write the IsReferenceParameter attribute,
            // and that's good for a consistent comparable form
            ParameterHeader.WriteStartHeader(writer, this, AddressingVersion.WSAddressingAugust2004);
            ParameterHeader.WriteHeaderContents(writer, this);
            writer.WriteEndElement();
            buffer.CloseSection();
            buffer.Close();
            return(buffer.GetReader(0));
        }
示例#16
0
        public override XmlDictionaryReader GetHeaderReader()
        {
            XmlDictionaryReader reader = buffer.GetReader(bufferIndex);

            // See if we need to move past the enclosing envelope/header
            if (streamed)
            {
                reader.MoveToContent();
                reader.Read(); // Envelope
                reader.Read(); // Header
                reader.MoveToContent();
            }
            return(reader);
        }
示例#17
0
        private bool InferHasDetail(XmlBuffer detail)
        {
            bool flag = false;

            if (detail != null)
            {
                XmlDictionaryReader reader = detail.GetReader(0);
                if (!reader.IsEmptyElement && reader.Read())
                {
                    flag = reader.MoveToContent() != XmlNodeType.EndElement;
                }
                reader.Close();
            }
            return(flag);
        }
示例#18
0
        bool InferHasDetail(XmlBuffer detail)
        {
            bool hasDetail = false;

            if (detail != null)
            {
                XmlDictionaryReader reader = detail.GetReader(0);
                if (!reader.IsEmptyElement && reader.Read()) // check if the detail element contains data
                {
                    hasDetail = (reader.MoveToContent() != XmlNodeType.EndElement);
                }
                reader.Dispose();
            }
            return(hasDetail);
        }
示例#19
0
        public override Message CreateMessage()
        {
            if (closed)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateBufferDisposedException());
            }

            Message msg;

            if (isNullMessage)
            {
                msg = new NullMessage();
            }
            else
            {
                msg = Message.CreateMessage(msgBuffer.GetReader(0), int.MaxValue, version);
            }

            lock (ThisLock)
            {
                msg.Properties.CopyProperties(properties);
            }

            for (int i = 0; i < understoodHeaders.Length; ++i)
            {
                if (understoodHeaders[i])
                {
                    msg.Headers.AddUnderstood(i);
                }
            }

            if (to != null)
            {
                msg.Headers.To = to;
            }

            if (action != null)
            {
                msg.Headers.Action = action;
            }

            return(msg);
        }
示例#20
0
        internal virtual XmlDictionaryReader GetReaderAtHeader()
        {
            XmlBuffer           buffer = new XmlBuffer(0x7fffffff);
            XmlDictionaryWriter writer = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            this.WriteStartEnvelope(writer);
            MessageHeaders headers = this.Headers;

            for (int i = 0; i < headers.Count; i++)
            {
                headers.WriteHeader(i, writer);
            }
            writer.WriteEndElement();
            writer.WriteEndElement();
            buffer.CloseSection();
            buffer.Close();
            XmlDictionaryReader reader = buffer.GetReader(0);

            reader.ReadStartElement();
            reader.MoveToStartElement();
            return(reader);
        }
示例#21
0
        public void WriteBodyToSignThenEncrypt(Stream canonicalStream, EncryptedData encryptedData, SymmetricAlgorithm algorithm)
        {
            XmlBuffer           buffer = new XmlBuffer(0x7fffffff);
            XmlDictionaryWriter writer = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            this.WriteBodyToSignThenEncryptWithFragments(canonicalStream, false, null, encryptedData, algorithm, writer);
            ((IFragmentCapableXmlDictionaryWriter)writer).WriteFragment(this.startBodyFragment.GetBuffer(), 0, (int)this.startBodyFragment.Length);
            ((IFragmentCapableXmlDictionaryWriter)writer).WriteFragment(this.endBodyFragment.GetBuffer(), 0, (int)this.endBodyFragment.Length);
            buffer.CloseSection();
            buffer.Close();
            this.startBodyFragment = null;
            this.endBodyFragment   = null;
            XmlDictionaryReader reader = buffer.GetReader(0);

            reader.MoveToContent();
            this.bodyPrefix = reader.Prefix;
            if (reader.HasAttributes)
            {
                this.bodyAttributes = System.IdentityModel.XmlAttributeHolder.ReadAttributes(reader);
            }
            reader.Close();
        }
示例#22
0
        public void WriteBodyToSignThenEncrypt(Stream canonicalStream, EncryptedData encryptedData, SymmetricAlgorithm algorithm)
        {
            XmlBuffer           buffer            = new XmlBuffer(int.MaxValue);
            XmlDictionaryWriter fragmentingWriter = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);

            WriteBodyToSignThenEncryptWithFragments(canonicalStream, false, null, encryptedData, algorithm, fragmentingWriter);
            ((IFragmentCapableXmlDictionaryWriter)fragmentingWriter).WriteFragment(_startBodyFragment.GetBuffer(), 0, (int)_startBodyFragment.Length);
            ((IFragmentCapableXmlDictionaryWriter)fragmentingWriter).WriteFragment(_endBodyFragment.GetBuffer(), 0, (int)_endBodyFragment.Length);
            buffer.CloseSection();
            buffer.Close();

            _startBodyFragment = null;
            _endBodyFragment   = null;

            XmlDictionaryReader reader = buffer.GetReader(0);

            reader.MoveToContent();
            _bodyPrefix = reader.Prefix;
            if (reader.HasAttributes)
            {
                _bodyAttributes = XmlAttributeHolder.ReadAttributes(reader);
            }
            reader.Close();
        }
示例#23
0
 public SecurityVerifiedMessage(Message messageToProcess, ReceiveSecurityHeader securityHeader)
     : base(messageToProcess)
 {
     ReceivedSecurityHeader = securityHeader;
     if (securityHeader.RequireMessageProtection)
     {
         XmlDictionaryReader messageReader;
         if (InnerMessage is BufferedMessage bufferedMessage && Headers.ContainsOnlyBufferedMessageHeaders)
         {
             messageReader = bufferedMessage.GetMessageReader();
         }
         else
         {
             _messageBuffer = new XmlBuffer(int.MaxValue);
             XmlDictionaryWriter writer = _messageBuffer.OpenSection(ReceivedSecurityHeader.ReaderQuotas);
             InnerMessage.WriteMessage(writer);
             _messageBuffer.CloseSection();
             _messageBuffer.Close();
             messageReader = _messageBuffer.GetReader(0);
         }
         MoveToSecurityHeader(messageReader, securityHeader.HeaderIndex, true);
         _cachedReaderAtSecurityHeader = messageReader;
         _state = BodyState.Buffered;
     }
示例#24
0
        public async Task <XmlDictionaryReader> GetReaderAtContentAsync()
        {
            await EnsureContentBufferAsync().ConfigureAwait(false);

            return(_contentBuffer.GetReader(0));
        }
        public void WriteBodyToSignThenEncrypt(Stream canonicalStream, EncryptedData encryptedData, SymmetricAlgorithm algorithm)
        {
            XmlBuffer buffer = new XmlBuffer(int.MaxValue);
            XmlDictionaryWriter fragmentingWriter = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);
            WriteBodyToSignThenEncryptWithFragments(canonicalStream, false, null, encryptedData, algorithm, fragmentingWriter);
            ((IFragmentCapableXmlDictionaryWriter)fragmentingWriter).WriteFragment(this.startBodyFragment.GetBuffer(), 0, (int)this.startBodyFragment.Length);
            ((IFragmentCapableXmlDictionaryWriter)fragmentingWriter).WriteFragment(this.endBodyFragment.GetBuffer(), 0, (int)this.endBodyFragment.Length);
            buffer.CloseSection();
            buffer.Close();

            this.startBodyFragment = null;
            this.endBodyFragment = null;

            XmlDictionaryReader reader = buffer.GetReader(0);
            reader.MoveToContent();
            this.bodyPrefix = reader.Prefix;
            if (reader.HasAttributes)
            {
                this.bodyAttributes = XmlAttributeHolder.ReadAttributes(reader);
            }
            reader.Close();
        }
示例#26
0
        public async Task <XmlDictionaryReader> GetReaderAtContent()
        {
            await EnsureContentBufferAsync();

            return(_contentBuffer.GetReader(0));
        }
示例#27
0
 public override XmlDictionaryReader GetAddressHeaderReader()
 {
     return(buffer.GetReader(0));
 }
示例#28
0
 public XmlDictionaryReader GetReaderAtContent()
 {
     EnsureContentBuffer();
     return(_contentBuffer.GetReader(0));
 }