Example #1
0
        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        {
            if (IsDisposed)
            {
                throw new ObjectDisposedException("", "MessageClosed.");
            }

            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }

            if (addComments)
            {
                writer.WriteComment("some comment");
            }

            while (!bodyReader.EOF)
            {
                writer.WriteNode(bodyReader, false);
                if (addComments)
                {
                    writer.WriteComment("some comment");
                }
            }

            bodyReader.Close();
        }
        void ValidateMessageBody(ref System.ServiceModel.Channels.Message message, bool isRequest)
        {
            if (!message.IsFault)
            {
                XmlDictionaryReaderQuotas quotas  = new XmlDictionaryReaderQuotas();
                XmlReader         bodyReader      = message.GetReaderAtBodyContents().ReadSubtree();
                XmlReaderSettings wrapperSettings = new XmlReaderSettings();
                wrapperSettings.CloseInput              = true;
                wrapperSettings.Schemas                 = schemaSet;
                wrapperSettings.ValidationFlags         = XmlSchemaValidationFlags.None;
                wrapperSettings.ValidationType          = ValidationType.Schema;
                wrapperSettings.ValidationEventHandler +=
                    new ValidationEventHandler(InspectionValidationHandler);
                XmlReader wrappedReader = XmlReader.Create(bodyReader, wrapperSettings);

                // pull body into a memory backed writer to validate
                this.isRequest = isRequest;
                MemoryStream        memStream = new MemoryStream();
                XmlDictionaryWriter xdw       = XmlDictionaryWriter.CreateBinaryWriter(memStream);
                xdw.WriteNode(wrappedReader, false);
                xdw.Flush(); memStream.Position = 0;
                XmlDictionaryReader xdr = XmlDictionaryReader.CreateBinaryReader(memStream, quotas);

                // reconstruct the message with the validated body
                Message replacedMessage = Message.CreateMessage(message.Version, null, xdr);
                replacedMessage.Headers.CopyHeadersFrom(message.Headers);
                replacedMessage.Properties.CopyProperties(message.Properties);
                message = replacedMessage;
            }
        }
Example #3
0
        public byte[] CanonicalizeUsingDictionaryWriter(XmlReader reader)
        {
            _canonicalWriterStream.Seek(0, SeekOrigin.Begin);
            _canonicalWriterStream.SetLength(0);

            MemoryStream        writerStream = new MemoryStream();
            XmlDictionaryWriter dicWriter    = XmlDictionaryWriter.CreateTextWriter(writerStream);

            dicWriter.WriteStartElement("Foo");
            if (_tokenizedInclusivePrefixes != null)
            {
                // Populate the Canonicalizer with prefix that are already read in
                // by the reader.
                foreach (string inclusivePrefix in _tokenizedInclusivePrefixes)
                {
                    string ns = reader.LookupNamespace(inclusivePrefix);
                    if (ns != null)
                    {
                        dicWriter.WriteXmlnsAttribute(inclusivePrefix, ns);
                    }
                }
            }

            dicWriter.StartCanonicalization(_canonicalWriterStream, _includeComments, _tokenizedInclusivePrefixes);
            reader.MoveToContent();
            dicWriter.WriteNode(reader, false);

            dicWriter.EndCanonicalization();
            dicWriter.WriteEndElement();

            return(_canonicalWriterStream.ToArray());
        }
Example #4
0
        internal static XmlBuffer ReadExtensions(XmlDictionaryReader reader, AddressingVersion version, XmlBuffer buffer, out EndpointIdentity identity, out int section)
        {
            if (reader == null)
            {
                identity = null;
                section  = -1;
                return(buffer);
            }

            // EndpointIdentity and extensions
            identity = null;
            XmlDictionaryWriter bufferWriter = null;

            reader.MoveToContent();
            while (reader.IsStartElement())
            {
                if (reader.IsStartElement(XD.AddressingDictionary.Identity, XD.AddressingDictionary.IdentityExtensionNamespace))
                {
                    if (identity != null)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(SR.UnexpectedDuplicateElement, XD.AddressingDictionary.Identity.Value, XD.AddressingDictionary.IdentityExtensionNamespace.Value)));
                    }

                    identity = EndpointIdentity.ReadIdentity(reader);
                }
                else if (version != null && reader.NamespaceURI == version.Namespace)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(SR.AddressingExtensionInBadNS, reader.LocalName, reader.NamespaceURI)));
                }
                else
                {
                    if (bufferWriter == null)
                    {
                        if (buffer == null)
                        {
                            buffer = new XmlBuffer(short.MaxValue);
                        }

                        bufferWriter = buffer.OpenSection(reader.Quotas);
                        bufferWriter.WriteStartElement(DummyName, DummyNamespace);
                    }

                    bufferWriter.WriteNode(reader, true);
                }
                reader.MoveToContent();
            }

            if (bufferWriter != null)
            {
                bufferWriter.WriteEndElement();
                buffer.CloseSection();
                section = buffer.SectionCount - 1;
            }
            else
            {
                section = -1;
            }

            return(buffer);
        }
Example #5
0
        void ValidateMessageBody(ref System.ServiceModel.Channels.Message message, bool isRequest)
        {
            if (!message.IsFault)
            {
                XmlDictionaryReaderQuotas quotas =
                    new XmlDictionaryReaderQuotas();
                XmlReader         bodyReader      = message.GetReaderAtBodyContents().ReadSubtree();
                XmlReaderSettings wrapperSettings =
                    new XmlReaderSettings();
                wrapperSettings.CloseInput      = true;
                wrapperSettings.Schemas         = EntityBase <object> .Schemas;
                wrapperSettings.ValidationFlags =
                    XmlSchemaValidationFlags.None;
                wrapperSettings.ValidationType          = ValidationType.Schema;
                wrapperSettings.ValidationEventHandler += new ValidationEventHandler(InspectionValidationHandler);
                XmlReader wrappedReader = XmlReader.Create(bodyReader,
                                                           wrapperSettings);

                // pull body into a memory backed writer to validate
                this.isRequest = isRequest;
                MemoryStream        memStream = new MemoryStream();
                XmlDictionaryWriter xdw       = XmlDictionaryWriter.CreateBinaryWriter(memStream);
                xdw.WriteNode(wrappedReader, false);
                xdw.Flush(); memStream.Position = 0;
                XmlDictionaryReader xdr =
                    XmlDictionaryReader.CreateBinaryReader(memStream, quotas);
            }
        }
Example #6
0
        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        {
            switch (_state)
            {
            case BodyState.Created:
                InnerMessage.WriteBodyContents(writer);
                return;

            case BodyState.Signed:
            case BodyState.EncryptedThenSigned:
                XmlDictionaryReader reader = _fullBodyBuffer.GetReader(0);
                reader.ReadStartElement();
                while (reader.NodeType != XmlNodeType.EndElement)
                {
                    writer.WriteNode(reader, false);
                }

                reader.ReadEndElement();
                reader.Close();
                return;

            case BodyState.Encrypted:
            case BodyState.SignedThenEncrypted:
                throw ExceptionHelper.PlatformNotSupported();

            default:
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateBadStateException(nameof(OnWriteBodyContents)));
            }
        }
        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        {
            if (!IsEmpty)
            {
                if (!isInboundRequest)
                {
                    writer.WriteStartElement(IsXmlRpcMethodCall ? XmlRpcProtocol.MethodCall : XmlRpcProtocol.MethodResponse);

                    if (IsXmlRpcMethodCall)
                    {
                        writer.WriteStartElement(XmlRpcProtocol.MethodName);
                        writer.WriteString((string)properties["XmlRpcMethodName"]);
                        writer.WriteEndElement();
                    }
                }
                writer.WriteNode(bodyReader, true);

                if (!isInboundRequest)
                {
                    writer.WriteEndElement();
                }

                writer.Flush();
            }
        }
Example #8
0
 public static void WriteNodeToWriter(byte[] buffer, XmlDictionaryWriter writer)
 {
     using (XmlDictionaryReader reader = Utility.CreateReader(buffer))
     {
         writer.WriteNode((XmlReader)reader, false);
     }
 }
Example #9
0
 protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 {
     foreach (XmlNode node in _usageReceipt.ChildNodes[0].ChildNodes)
     {
         writer.WriteNode(node.CreateNavigator(), false);
     }
 }
Example #10
0
        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        {
            switch (this.state)
            {
            case BodyState.Created:
                this.InnerMessage.WriteBodyContents(writer);
                return;

            case BodyState.Signed:
                using (XmlDictionaryReader reader = Utility.CreateReader(this.fullBodyBuffer))
                {
                    reader.MoveToStartElement();
                    reader.ReadStartElement();
                    while (reader.NodeType != XmlNodeType.EndElement)
                    {
                        writer.WriteNode(reader, false);
                    }

                    reader.ReadEndElement();
                }
                return;

            default:
                throw new ArgumentException("Can't write the message because it is in a bad or unknown state");
            }
        }
Example #11
0
 protected override void  OnWriteBodyContents(XmlDictionaryWriter writer)
 {
     if (!IsEmpty)
     {
         writer.WriteNode(_bodyReader, true);
     }
 }
 public XmlSyndicationContent(XmlReader reader)
 {
     if (reader == null)
     {
         throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("reader");
     }
     SyndicationFeedFormatter.MoveToStartElement(reader);
     if (reader.HasAttributes)
     {
         while (reader.MoveToNextAttribute())
         {
             string localName    = reader.LocalName;
             string namespaceURI = reader.NamespaceURI;
             string str3         = reader.Value;
             if ((localName == "type") && (namespaceURI == string.Empty))
             {
                 this.type = str3;
             }
             else if (!FeedUtils.IsXmlns(localName, namespaceURI))
             {
                 base.AttributeExtensions.Add(new XmlQualifiedName(localName, namespaceURI), str3);
             }
         }
         reader.MoveToElement();
     }
     this.type          = string.IsNullOrEmpty(this.type) ? "text/xml" : this.type;
     this.contentBuffer = new XmlBuffer(0x7fffffff);
     using (XmlDictionaryWriter writer = this.contentBuffer.OpenSection(XmlDictionaryReaderQuotas.Max))
     {
         writer.WriteNode(reader, false);
     }
     this.contentBuffer.CloseSection();
     this.contentBuffer.Close();
 }
 public override void WriteObjectContent(XmlDictionaryWriter writer, object graph)
 {
     if (writer == null) throw new ArgumentNullException("writer");
     if (writer.WriteState != WriteState.Element)
         throw new SerializationException(string.Format("WriteState '{0}' not valid. Caller must write start element before serializing in contentOnly mode.",
             writer.WriteState));
     using (MemoryStream memoryStream = new MemoryStream())
     {
         using (XmlDictionaryWriter bufferWriter = XmlDictionaryWriter.CreateTextWriter(memoryStream, Encoding.UTF8))
         {
             serializer.Serialize(bufferWriter, graph);
             bufferWriter.Flush();
             memoryStream.Position = 0;
             using (XmlReader reader = new XmlTextReader(memoryStream))
             {
                 reader.MoveToContent();
                 writer.WriteAttributes(reader, false);
                 if (reader.Read()) // move off start node (we want to skip it)
                 {
                     while (reader.NodeType != XmlNodeType.EndElement) // also skip end node.
                         writer.WriteNode(reader, false); // this will take us to the start of the next child node, or the end node.
                     reader.ReadEndElement(); // not necessary, but clean
                 }
             }
         }
     }
 }
Example #14
0
 // copy all of reader to writer
 static internal void Copy(XmlDictionaryWriter writer, XmlDictionaryReader reader)
 {
     while (!Done(reader))
     {
         writer.WriteNode(reader, true);
     }
 }
Example #15
0
        // Saves the element in the reader to the buffer (attributes preserved)
        // Type is populated from type attribute on reader
        // Reader must be positioned at an element
        public XmlSyndicationContent(XmlReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            SyndicationFeedFormatter.MoveToStartElement(reader);
            if (reader.HasAttributes)
            {
                while (reader.MoveToNextAttribute())
                {
                    string name  = reader.LocalName;
                    string ns    = reader.NamespaceURI;
                    string value = reader.Value;
                    if (name == Atom10Constants.TypeTag && ns == string.Empty)
                    {
                        _type = value;
                    }
                    else if (!FeedUtils.IsXmlns(name, ns))
                    {
                        base.AttributeExtensions.Add(new XmlQualifiedName(name, ns), value);
                    }
                }
                reader.MoveToElement();
            }
            _type          = string.IsNullOrEmpty(_type) ? Atom10Constants.XmlMediaType : _type;
            _contentBuffer = new XmlBuffer(int.MaxValue);
            using (XmlDictionaryWriter writer = _contentBuffer.OpenSection(XmlDictionaryReaderQuotas.Max))
            {
                writer.WriteNode(reader, false);
            }
            _contentBuffer.CloseSection();
            _contentBuffer.Close();
        }
        internal static async Task <Tuple <XmlBuffer, XmlDictionaryWriter> > CreateBufferIfRequiredAndWriteNodeAsync(XmlBuffer buffer, XmlDictionaryWriter extWriter, XmlReader reader, int maxExtensionSize)
        {
            if (buffer == null)
            {
                buffer    = new XmlBuffer(maxExtensionSize);
                extWriter = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);
                extWriter.WriteStartElement(Rss20Constants.ExtensionWrapperTag);
            }

            XmlDictionaryReader dictionaryReader = reader as XmlDictionaryReader;

            if (dictionaryReader != null)
            {
                // Reimplementing WriteNode for XmlDictionaryWriter asynchronously depends on multiple internal methods
                // so isn't feasible to reimplement here. As the primary scenario will be usage with an XmlReader which
                // isn't an XmlDictionaryReader, deferring to the synchronous implementation is a reasonable fallback.
                extWriter.WriteNode(reader, false);
            }
            else
            {
                await extWriter.WriteNodeAsync(reader, false);
            }

            return(Tuple.Create(buffer, extWriter));
        }
Example #17
0
        public BufferedHeader(MessageVersion version, XmlBuffer buffer, XmlDictionaryReader reader, XmlAttributeHolder[] envelopeAttributes, XmlAttributeHolder[] headerAttributes)
        {
            this.streamed = true;
            this.buffer   = buffer;
            this.version  = version;
            MessageHeader.GetHeaderAttributes(reader, version, out this.actor, out this.mustUnderstand, out this.relay, out this.isRefParam);
            this.name        = reader.LocalName;
            this.ns          = reader.NamespaceURI;
            this.bufferIndex = buffer.SectionCount;
            XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas);

            writer.WriteStartElement("Envelope");
            if (envelopeAttributes != null)
            {
                XmlAttributeHolder.WriteAttributes(envelopeAttributes, writer);
            }
            writer.WriteStartElement("Header");
            if (headerAttributes != null)
            {
                XmlAttributeHolder.WriteAttributes(headerAttributes, writer);
            }
            writer.WriteNode(reader, false);
            writer.WriteEndElement();
            writer.WriteEndElement();
            buffer.CloseSection();
        }
Example #18
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();
            }
        }
Example #19
0
        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        {
            switch (this.state)
            {
            case BodyState.Created:
                this.InnerMessage.WriteBodyContents(writer);
                return;

            case BodyState.Signed:
            case BodyState.EncryptedThenSigned:
                XmlDictionaryReader reader = fullBodyBuffer.GetReader(0);
                reader.ReadStartElement();
                while (reader.NodeType != XmlNodeType.EndElement)
                {
                    writer.WriteNode(reader, false);
                }
                reader.ReadEndElement();
                reader.Close();
                return;

            case BodyState.Encrypted:
            case BodyState.SignedThenEncrypted:
                this.encryptedBodyContent.WriteTo(writer, ServiceModelDictionaryManager.Instance);
                break;

            default:
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateBadStateException(nameof(OnWriteBodyContents)));
            }
        }
Example #20
0
        public BufferedHeader(MessageVersion version, XmlBuffer buffer, XmlDictionaryReader reader, XmlAttributeHolder[] envelopeAttributes, XmlAttributeHolder[] headerAttributes)
        {
            streamed     = true;
            this.buffer  = buffer;
            this.version = version;
            GetHeaderAttributes(reader, version, out actor, out mustUnderstand, out relay, out isRefParam);
            name = reader.LocalName;
            ns   = reader.NamespaceURI;
            Fx.Assert(name != null, "");
            Fx.Assert(ns != null, "");
            bufferIndex = buffer.SectionCount;
            XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas);

            // Write an enclosing Envelope tag
            writer.WriteStartElement(MessageStrings.Envelope);
            if (envelopeAttributes != null)
            {
                XmlAttributeHolder.WriteAttributes(envelopeAttributes, writer);
            }

            // Write and enclosing Header tag
            writer.WriteStartElement(MessageStrings.Header);
            if (headerAttributes != null)
            {
                XmlAttributeHolder.WriteAttributes(headerAttributes, writer);
            }

            writer.WriteNode(reader, false);

            writer.WriteEndElement();
            writer.WriteEndElement();

            buffer.CloseSection();
        }
        public void WriteTo(Stream canonicalStream)
        {
            if (this.reader != null)
            {
                XmlDictionaryReader dicReader = this.reader as XmlDictionaryReader;
                if ((dicReader != null) && (dicReader.CanCanonicalize))
                {
                    dicReader.MoveToContent();
                    dicReader.StartCanonicalization(canonicalStream, this.includeComments, this.inclusivePrefixes);
                    dicReader.Skip();
                    dicReader.EndCanonicalization();
                }
                else
                {
                    XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(Stream.Null);
                    if (this.inclusivePrefixes != null)
                    {
                        // Add a dummy element at the top and populate the namespace
                        // declaration of all the inclusive prefixes.
                        writer.WriteStartElement("a", reader.LookupNamespace(String.Empty));
                        for (int i = 0; i < this.inclusivePrefixes.Length; ++i)
                        {
                            string ns = reader.LookupNamespace(this.inclusivePrefixes[i]);
                            if (ns != null)
                            {
                                writer.WriteXmlnsAttribute(this.inclusivePrefixes[i], ns);
                            }
                        }
                    }
                    writer.StartCanonicalization(canonicalStream, this.includeComments, this.inclusivePrefixes);
                    if (reader is WrappedReader)
                    {
                        ((WrappedReader)reader).XmlTokens.GetWriter().WriteTo(writer, new DictionaryManager());
                    }
                    else
                    {
                        writer.WriteNode(reader, false);
                    }
                    writer.Flush();
                    writer.EndCanonicalization();

                    if (this.inclusivePrefixes != null)
                    {
                        writer.WriteEndElement();
                    }

                    writer.Close();
                }
                if (this.closeReadersAfterProcessing)
                {
                    this.reader.Close();
                }
                this.reader = null;
            }
            else
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.NoInputIsSetForCanonicalization)));
            }
        }
Example #22
0
            protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
            {
                XmlDictionaryReader reader = this.originalMessage.GetReaderAtBodyContents();

                // Write root StartElement
                writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                writer.WriteAttributes(reader, true);
                reader.ReadStartElement();

                // Write QueryResult StartElement
                writer.WriteStartElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
                writer.WriteAttributes(reader, true);

                // Write QueryResult content
                string nodeName = reader.LocalName;

                reader.Read();

                while (reader.NodeType != XmlNodeType.EndElement || reader.Name != nodeName)
                {
                    XmlReader subtree = reader.ReadSubtree();
                    writer.WriteNode(subtree, false);
                    reader.ReadEndElement();
                }

                // Insert metadata start
                writer.WriteStartElement("Metadata");
                writer.WriteAttributeString("type", "array");
                // This two foreach loops are to ensure we write the return entity of the query first, then all the rest.
                // This is a requirement of the RIA/JS client side implementation. If modifying this, client side needs update too.
                foreach (ServiceMetadataGenerator.TypeMetadata map in ServiceMetadataGenerator.EntitiesMetadata)
                {
                    if (map.Name == this.entityTypeName)
                    {
                        writer.WriteStartElement("item");
                        writer.WriteAttributeString("type", "object");
                        map.WriteJson(writer);
                        writer.WriteEndElement();
                        break;
                    }
                }
                foreach (ServiceMetadataGenerator.TypeMetadata map in ServiceMetadataGenerator.EntitiesMetadata)
                {
                    if (map.Name != this.entityTypeName)
                    {
                        writer.WriteStartElement("item");
                        writer.WriteAttributeString("type", "object");
                        map.WriteJson(writer);
                        writer.WriteEndElement();
                    }
                }
                writer.WriteEndElement();
                // Insert metadata end

                // Close QueryResult
                writer.WriteEndElement();
                // Close root
                writer.WriteEndElement();
            }
Example #23
0
        protected override void OnWriteBodyContents(
            XmlDictionaryWriter writer)
        {
            XmlReader r = reader ?? XmlReader.Create(new StringReader(xml));

            r.MoveToContent();
            writer.WriteNode(r, false);
        }
 protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
 {
     using (var sr = new System.IO.StringReader(_content))
         using (var xr = XmlReader.Create(sr))
         {
             writer.WriteNode(xr, true);
         }
 }
Example #25
0
        private void WriteContentsTo200408(XmlDictionaryWriter writer)
        {
            writer.WriteStartElement(XD.AddressingDictionary.Address, XD.Addressing200408Dictionary.Namespace);
            if (this.isAnonymous)
            {
                writer.WriteString(XD.Addressing200408Dictionary.Anonymous);
            }
            else
            {
                if (this.isNone)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("addressingVersion", System.ServiceModel.SR.GetString("SFxNone2004"));
                }
                writer.WriteString(this.Uri.AbsoluteUri);
            }
            writer.WriteEndElement();
            if ((this.headers != null) && this.headers.HasReferenceProperties)
            {
                writer.WriteStartElement(XD.AddressingDictionary.ReferenceProperties, XD.Addressing200408Dictionary.Namespace);
                this.headers.WriteReferencePropertyContentsTo(writer);
                writer.WriteEndElement();
            }
            if ((this.headers != null) && this.headers.HasNonReferenceProperties)
            {
                writer.WriteStartElement(XD.AddressingDictionary.ReferenceParameters, XD.Addressing200408Dictionary.Namespace);
                this.headers.WriteNonReferencePropertyContentsTo(writer);
                writer.WriteEndElement();
            }
            XmlDictionaryReader readerAtSection = null;

            if (this.pspSection >= 0)
            {
                readerAtSection = GetReaderAtSection(this.buffer, this.pspSection);
                Copy(writer, readerAtSection);
            }
            readerAtSection = null;
            if (this.metadataSection >= 0)
            {
                readerAtSection = GetReaderAtSection(this.buffer, this.metadataSection);
                Copy(writer, readerAtSection);
            }
            if (this.Identity != null)
            {
                this.Identity.WriteTo(writer);
            }
            if (this.extensionSection >= 0)
            {
                readerAtSection = GetReaderAtSection(this.buffer, this.extensionSection);
                while (readerAtSection.IsStartElement())
                {
                    if (readerAtSection.NamespaceURI == AddressingVersion.WSAddressingAugust2004.Namespace)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(readerAtSection, System.ServiceModel.SR.GetString("AddressingExtensionInBadNS", new object[] { readerAtSection.LocalName, readerAtSection.NamespaceURI })));
                    }
                    writer.WriteNode(readerAtSection, true);
                }
            }
        }
Example #26
0
 protected override void OnBodyToString(XmlDictionaryWriter writer)
 {
     using (XmlDictionaryReader reader = this.GetBufferedReaderAtBody())
     {
         if (this.Version == MessageVersion.None)
         {
             writer.WriteNode(reader, false);
         }
         else if (!reader.IsEmptyElement)
         {
             reader.ReadStartElement();
             while (reader.NodeType != XmlNodeType.EndElement)
             {
                 writer.WriteNode(reader, false);
             }
         }
     }
 }
Example #27
0
 public override void WriteTokenCore(XmlDictionaryWriter writer, SecurityToken token)
 {
     if (token is BufferedGenericXmlSecurityToken bufferedXmlToken && bufferedXmlToken.TokenXmlBuffer != null)
     {
         using (XmlDictionaryReader reader = bufferedXmlToken.TokenXmlBuffer.GetReader(0))
         {
             writer.WriteNode(reader, false);
         }
     }
Example #28
0
        void WriteContentsTo10(XmlDictionaryWriter writer)
        {
            // Address
            writer.WriteStartElement(XD.AddressingDictionary.Address, XD.Addressing10Dictionary.Namespace);
            if (isAnonymous)
            {
                writer.WriteString(XD.Addressing10Dictionary.Anonymous);
            }
            else if (isNone)
            {
                writer.WriteString(XD.Addressing10Dictionary.NoneAddress);
            }
            else
            {
                writer.WriteString(Uri.AbsoluteUri);
            }
            writer.WriteEndElement();

            // Headers
            if (headers != null && headers.Count > 0)
            {
                writer.WriteStartElement(XD.AddressingDictionary.ReferenceParameters, XD.Addressing10Dictionary.Namespace);
                headers.WriteContentsTo(writer);
                writer.WriteEndElement();
            }

            // Metadata
            if (metadataSection >= 0)
            {
                XmlDictionaryReader reader = GetReaderAtSection(buffer, metadataSection);
                writer.WriteStartElement(XD.Addressing10Dictionary.Metadata, XD.Addressing10Dictionary.Namespace);
                Copy(writer, reader);
                writer.WriteEndElement();
            }

            // EndpointIdentity
            if (Identity != null)
            {
                Identity.WriteTo(writer);
            }

            // Extensions
            if (extensionSection >= 0)
            {
                XmlDictionaryReader reader = GetReaderAtSection(buffer, extensionSection);
                while (reader.IsStartElement())
                {
                    if (reader.NamespaceURI == AddressingVersion.WSAddressing10.Namespace)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(SR.AddressingExtensionInBadNS, reader.LocalName, reader.NamespaceURI)));
                    }

                    writer.WriteNode(reader, true);
                }
            }
        }
 internal static void CreateBufferIfRequiredAndWriteNode(ref XmlBuffer buffer, ref XmlDictionaryWriter extWriter, XmlReader reader, int maxExtensionSize)
 {
     if (buffer == null)
     {
         buffer    = new XmlBuffer(maxExtensionSize);
         extWriter = buffer.OpenSection(XmlDictionaryReaderQuotas.Max);
         extWriter.WriteStartElement(Rss20Constants.ExtensionWrapperTag);
     }
     extWriter.WriteNode(reader, false);
 }
Example #30
0
        protected override void OnWriteBodyContents(
            XmlDictionaryWriter writer)
        {
            XmlDictionaryReader reader = GetReaderAtBodyContents();

            while (!reader.EOF && reader.NodeType != XmlNodeType.EndElement)
            {
                writer.WriteNode(reader, false);
            }
        }