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(); }
private void PossiblyPopulateBuffer(XmlDictionaryReader reader, ref XmlBuffer buffer, out int section) { if (reader == null) { section = -1; } else { if (buffer == null) { buffer = new XmlBuffer(0x7fff); } section = buffer.SectionCount; XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas); writer.WriteStartElement("Dummy", "http://Dummy"); Copy(writer, reader); buffer.CloseSection(); } }
internal BodyWriter OnCreateBufferedCopy(int maxBufferSize, XmlDictionaryReaderQuotas quotas) { XmlBuffer buffer = new XmlBuffer(maxBufferSize); using (XmlDictionaryWriter writer = buffer.OpenSection(quotas)) { writer.WriteStartElement("a"); this.OnWriteBodyContents(writer); writer.WriteEndElement(); } buffer.CloseSection(); buffer.Close(); return new BufferedBodyWriter(buffer); }
public static XmlDictionaryReader GetReaderAtDetailContentsFeb2005(string detailName, string detailNamespace, XmlDictionaryReader headerReader) { XmlDictionaryReader reader; try { WsrmFeb2005Dictionary dictionary = XD.WsrmFeb2005Dictionary; XmlDictionaryString namespaceUri = dictionary.Namespace; XmlBuffer buffer = null; int sectionIndex = 0; int depth = headerReader.Depth; headerReader.ReadFullStartElement(dictionary.SequenceFault, namespaceUri); while (headerReader.Depth > depth) { if (((headerReader.NodeType == XmlNodeType.Element) && (headerReader.NamespaceURI == detailNamespace)) && (headerReader.LocalName == detailName)) { if (buffer != null) { return null; } buffer = new XmlBuffer(0x7fffffff); try { sectionIndex = buffer.SectionCount; buffer.OpenSection(headerReader.Quotas).WriteNode(headerReader, false); continue; } finally { buffer.CloseSection(); } } if (headerReader.Depth == depth) { break; } headerReader.Read(); } if (buffer == null) { return null; } buffer.Close(); reader = buffer.GetReader(sectionIndex); } finally { headerReader.Close(); } return reader; }
public void SetMetadataReader(XmlDictionaryReader reader) { _hasMetadata = true; _metadataBuffer = null; if (reader != null) { _metadataBuffer = new XmlBuffer(short.MaxValue); XmlDictionaryWriter writer = _metadataBuffer.OpenSection(reader.Quotas); writer.WriteStartElement(EndpointAddress.DummyName, EndpointAddress.DummyNamespace); EndpointAddress.Copy(writer, reader); _metadataBuffer.CloseSection(); _metadataBuffer.Close(); } }
private static XmlBuffer CreateXmlBuffer(XmlDictionaryReader unparsedExtensionsReader, int maxExtensionSize) { XmlBuffer buffer = new XmlBuffer(maxExtensionSize); using (XmlDictionaryWriter writer = buffer.OpenSection(unparsedExtensionsReader.Quotas)) { writer.WriteStartElement("extensionWrapper"); while (unparsedExtensionsReader.IsStartElement()) { writer.WriteNode(unparsedExtensionsReader, false); } writer.WriteEndElement(); } buffer.CloseSection(); buffer.Close(); return buffer; }
public static XmlDictionaryReader GetReaderAtDetailContentsFeb2005(string detailName, string detailNamespace, XmlDictionaryReader headerReader) { try { WsrmFeb2005Dictionary wsrmFeb2005Dictionary = XD.WsrmFeb2005Dictionary; XmlDictionaryString wsrmNs = wsrmFeb2005Dictionary.Namespace; XmlBuffer buffer = null; int index = 0; int depth = headerReader.Depth; headerReader.ReadFullStartElement(wsrmFeb2005Dictionary.SequenceFault, wsrmNs); while (headerReader.Depth > depth) { if ((headerReader.NodeType == XmlNodeType.Element) && (headerReader.NamespaceURI == detailNamespace) && (headerReader.LocalName == detailName)) { if (buffer != null) { return null; } buffer = new XmlBuffer(int.MaxValue); try { index = buffer.SectionCount; XmlDictionaryWriter writer = buffer.OpenSection(headerReader.Quotas); // WriteNode moves the reader to the next sibling. writer.WriteNode(headerReader, false); } finally { buffer.CloseSection(); } } else { if (headerReader.Depth == depth) break; headerReader.Read(); } } // Ensure at least one detail is found; if (buffer == null) { return null; } // Close causes a state change. It moves the buffer from Created to Reading. buffer.Close(); XmlDictionaryReader detailReader = buffer.GetReader(index); return detailReader; } finally { headerReader.Close(); } }
public BufferedHeader(MessageVersion version, XmlBuffer buffer, XmlDictionaryReader reader, XmlAttributeHolder[] envelopeAttributes, XmlAttributeHolder[] headerAttributes) { this.streamed = true; this.buffer = buffer; this.version = version; GetHeaderAttributes(reader, version, out this.actor, out this.mustUnderstand, out this.relay, out this.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(); }
private static bool ReadContentsFrom10(XmlDictionaryReader reader, out System.Uri uri, out AddressHeaderCollection headers, out EndpointIdentity identity, out XmlBuffer buffer, out int metadataSection, out int extensionSection) { buffer = null; extensionSection = -1; metadataSection = -1; if (!reader.IsStartElement(XD.AddressingDictionary.Address, XD.Addressing10Dictionary.Namespace)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, System.ServiceModel.SR.GetString("UnexpectedElementExpectingElement", new object[] { reader.LocalName, reader.NamespaceURI, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value }))); } string uriString = reader.ReadElementContentAsString(); if (reader.IsStartElement(XD.AddressingDictionary.ReferenceParameters, XD.Addressing10Dictionary.Namespace)) { headers = AddressHeaderCollection.ReadServiceParameters(reader); } else { headers = null; } if (reader.IsStartElement(XD.Addressing10Dictionary.Metadata, XD.Addressing10Dictionary.Namespace)) { reader.ReadFullStartElement(); buffer = new XmlBuffer(0x7fff); metadataSection = 0; XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas); writer.WriteStartElement("Dummy", "http://Dummy"); while ((reader.NodeType != XmlNodeType.EndElement) && !reader.EOF) { writer.WriteNode(reader, true); } writer.Flush(); buffer.CloseSection(); reader.ReadEndElement(); } buffer = ReadExtensions(reader, AddressingVersion.WSAddressing10, buffer, out identity, out extensionSection); if (buffer != null) { buffer.Close(); } if (uriString == "http://www.w3.org/2005/08/addressing/anonymous") { uri = AddressingVersion.WSAddressing10.AnonymousUri; if ((headers == null) && (identity == null)) { return true; } } else { if (uriString == "http://www.w3.org/2005/08/addressing/none") { uri = AddressingVersion.WSAddressing10.NoneUri; return false; } if (!System.Uri.TryCreate(uriString, UriKind.Absolute, out uri)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidUriValue", new object[] { uriString, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value }))); } } return false; }
static bool ReadContentsFrom10(XmlDictionaryReader reader, out Uri uri, out AddressHeaderCollection headers, out EndpointIdentity identity, out XmlBuffer buffer, out int metadataSection, out int extensionSection) { buffer = null; extensionSection = -1; metadataSection = -1; // Cache address string if (!reader.IsStartElement(XD.AddressingDictionary.Address, XD.Addressing10Dictionary.Namespace)) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.GetString(SR.UnexpectedElementExpectingElement, reader.LocalName, reader.NamespaceURI, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value))); string address = reader.ReadElementContentAsString(); // Headers if (reader.IsStartElement(XD.AddressingDictionary.ReferenceParameters, XD.Addressing10Dictionary.Namespace)) { headers = AddressHeaderCollection.ReadServiceParameters(reader); } else { headers = null; } // Metadata if (reader.IsStartElement(XD.Addressing10Dictionary.Metadata, XD.Addressing10Dictionary.Namespace)) { reader.ReadFullStartElement(); // the wsa10:Metadata element is never stored in the buffer buffer = new XmlBuffer(short.MaxValue); metadataSection = 0; XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas); writer.WriteStartElement(DummyName, DummyNamespace); while (reader.NodeType != XmlNodeType.EndElement && !reader.EOF) { writer.WriteNode(reader, true); } writer.Flush(); buffer.CloseSection(); reader.ReadEndElement(); } // Extensions buffer = ReadExtensions(reader, AddressingVersion.WSAddressing10, buffer, out identity, out extensionSection); if (buffer != null) { buffer.Close(); } // Process Address if (address == Addressing10Strings.Anonymous) { uri = AddressingVersion.WSAddressing10.AnonymousUri; if (headers == null && identity == null) { return true; } } else if (address == Addressing10Strings.NoneAddress) { uri = AddressingVersion.WSAddressing10.NoneUri; return false; } else { if (!Uri.TryCreate(address, UriKind.Absolute, out uri)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.InvalidUriValue, address, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value))); } } return false; }
public void SetMetadataReader(XmlDictionaryReader reader) { hasMetadata = true; metadataBuffer = null; if (reader != null) { metadataBuffer = new XmlBuffer(short.MaxValue); XmlDictionaryWriter writer = metadataBuffer.OpenSection(reader.Quotas); writer.WriteStartElement(EndpointAddress.DummyName, EndpointAddress.DummyNamespace); EndpointAddress.Copy(writer, reader); metadataBuffer.CloseSection(); metadataBuffer.Close(); } }
private static bool ReadContentsFrom10(XmlDictionaryReader reader, out System.Uri uri, out AddressHeaderCollection headers, out EndpointIdentity identity, out XmlBuffer buffer, out int metadataSection, out int extensionSection) { buffer = null; extensionSection = -1; metadataSection = -1; if (!reader.IsStartElement(XD.AddressingDictionary.Address, XD.Addressing10Dictionary.Namespace)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, System.ServiceModel.SR.GetString("UnexpectedElementExpectingElement", new object[] { reader.LocalName, reader.NamespaceURI, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value }))); } string uriString = reader.ReadElementContentAsString(); if (reader.IsStartElement(XD.AddressingDictionary.ReferenceParameters, XD.Addressing10Dictionary.Namespace)) { headers = AddressHeaderCollection.ReadServiceParameters(reader); } else { headers = null; } if (reader.IsStartElement(XD.Addressing10Dictionary.Metadata, XD.Addressing10Dictionary.Namespace)) { reader.ReadFullStartElement(); buffer = new XmlBuffer(0x7fff); metadataSection = 0; XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas); writer.WriteStartElement("Dummy", "http://Dummy"); while ((reader.NodeType != XmlNodeType.EndElement) && !reader.EOF) { writer.WriteNode(reader, true); } writer.Flush(); buffer.CloseSection(); reader.ReadEndElement(); } buffer = ReadExtensions(reader, AddressingVersion.WSAddressing10, buffer, out identity, out extensionSection); if (buffer != null) { buffer.Close(); } if (uriString == "http://www.w3.org/2005/08/addressing/anonymous") { uri = AddressingVersion.WSAddressing10.AnonymousUri; if ((headers == null) && (identity == null)) { return(true); } } else { if (uriString == "http://www.w3.org/2005/08/addressing/none") { uri = AddressingVersion.WSAddressing10.NoneUri; return(false); } if (!System.Uri.TryCreate(uriString, UriKind.Absolute, out uri)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidUriValue", new object[] { uriString, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value }))); } } return(false); }
private static bool ReadContentsFrom10(XmlDictionaryReader reader, out Uri uri, out AddressHeaderCollection headers, out EndpointIdentity identity, out XmlBuffer buffer, out int metadataSection, out int extensionSection) { buffer = null; extensionSection = -1; metadataSection = -1; // Cache address string if (!reader.IsStartElement(XD.AddressingDictionary.Address, XD.Addressing10Dictionary.Namespace)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(SR.UnexpectedElementExpectingElement, reader.LocalName, reader.NamespaceURI, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value))); } string address = reader.ReadElementContentAsString(); // Headers if (reader.IsStartElement(XD.AddressingDictionary.ReferenceParameters, XD.Addressing10Dictionary.Namespace)) { headers = AddressHeaderCollection.ReadServiceParameters(reader); } else { headers = null; } // Metadata if (reader.IsStartElement(XD.Addressing10Dictionary.Metadata, XD.Addressing10Dictionary.Namespace)) { reader.ReadFullStartElement(); // the wsa10:Metadata element is never stored in the buffer buffer = new XmlBuffer(short.MaxValue); metadataSection = 0; XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas); writer.WriteStartElement(DummyName, DummyNamespace); while (reader.NodeType != XmlNodeType.EndElement && !reader.EOF) { writer.WriteNode(reader, true); } writer.Flush(); buffer.CloseSection(); reader.ReadEndElement(); } // Extensions buffer = ReadExtensions(reader, AddressingVersion.WSAddressing10, buffer, out identity, out extensionSection); if (buffer != null) { buffer.Close(); } // Process Address if (address == Addressing10Strings.Anonymous) { uri = AddressingVersion.WSAddressing10.AnonymousUri; if (headers == null && identity == null) { return(true); } } else if (address == Addressing10Strings.NoneAddress) { uri = AddressingVersion.WSAddressing10.NoneUri; return(false); } else { if (!Uri.TryCreate(address, UriKind.Absolute, out uri)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.InvalidUriValue, address, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value))); } } return(false); }