public void SetExtensionReader(XmlDictionaryReader reader) { _hasExtension = true; _extensionBuffer = EndpointAddress.ReadExtensions(reader, null, null, out EndpointIdentity identity, out int tmp); if (_extensionBuffer != null) { _extensionBuffer.Close(); } if (identity != null) { Identity = identity; } }
static XmlDictionaryReader GetReaderAtSection(XmlBuffer buffer, int section) { if (buffer == null || section < 0) { return(null); } XmlDictionaryReader reader = buffer.GetReader(section); reader.MoveToContent(); Fx.Assert(reader.Name == DummyName, "EndpointAddress: Expected dummy element not found"); reader.Read(); // consume the dummy wrapper element 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(); } }
void PossiblyPopulateBuffer(XmlDictionaryReader reader, ref XmlBuffer buffer, out int section) { if (reader == null) { section = -1; } else { if (buffer == null) { buffer = new XmlBuffer(short.MaxValue); } section = buffer.SectionCount; XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas); writer.WriteStartElement(DummyName, DummyNamespace); Copy(writer, reader); buffer.CloseSection(); } }
EndpointAddress(AddressingVersion version, Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlBuffer buffer, int metadataSection, int extensionSection, int pspSection) { Init(version, uri, identity, headers, buffer, metadataSection, extensionSection, pspSection); }
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); }
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); }
void Init(AddressingVersion version, Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlBuffer buffer, int metadataSection, int extensionSection, int pspSection) { if (!uri.IsAbsoluteUri) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("uri", SR.UriMustBeAbsolute); } addressingVersion = version; this.uri = uri; this.identity = identity; this.headers = headers; this.buffer = buffer; this.metadataSection = metadataSection; this.extensionSection = extensionSection; this.pspSection = pspSection; if (version != null) { isAnonymous = uri == version.AnonymousUri; isNone = uri == version.NoneUri; } else { isAnonymous = object.ReferenceEquals(uri, AnonymousUri) || uri == AnonymousUri; isNone = object.ReferenceEquals(uri, NoneUri) || uri == NoneUri; } if (isAnonymous) { this.uri = AnonymousUri; } if (isNone) { this.uri = NoneUri; } }
void Init(Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlBuffer buffer, int metadataSection, int extensionSection, int pspSection) { Init(null, uri, identity, headers, buffer, metadataSection, extensionSection, pspSection); }
private static bool ReadContentsFrom200408(XmlDictionaryReader reader, out Uri uri, out AddressHeaderCollection headers, out EndpointIdentity identity, out XmlBuffer buffer, out int metadataSection, out int extensionSection, out int pspSection) { buffer = null; headers = null; extensionSection = -1; metadataSection = -1; pspSection = -1; // Cache address string reader.MoveToContent(); if (!reader.IsStartElement(XD.AddressingDictionary.Address, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(SR.UnexpectedElementExpectingElement, reader.LocalName, reader.NamespaceURI, XD.AddressingDictionary.Address.Value, XD.Addressing200408Dictionary.Namespace.Value))); } string address = reader.ReadElementContentAsString(); // ReferenceProperites reader.MoveToContent(); if (reader.IsStartElement(XD.AddressingDictionary.ReferenceProperties, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace)) { headers = AddressHeaderCollection.ReadServiceParameters(reader, true); } // ReferenceParameters reader.MoveToContent(); if (reader.IsStartElement(XD.AddressingDictionary.ReferenceParameters, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace)) { if (headers != null) { List <AddressHeader> headerList = new List <AddressHeader>(); foreach (AddressHeader ah in headers) { headerList.Add(ah); } AddressHeaderCollection tmp = AddressHeaderCollection.ReadServiceParameters(reader); foreach (AddressHeader ah in tmp) { headerList.Add(ah); } headers = new AddressHeaderCollection(headerList); } else { headers = AddressHeaderCollection.ReadServiceParameters(reader); } } XmlDictionaryWriter bufferWriter = null; // PortType reader.MoveToContent(); if (reader.IsStartElement(XD.AddressingDictionary.PortType, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace)) { if (bufferWriter == null) { if (buffer == null) { buffer = new XmlBuffer(short.MaxValue); } bufferWriter = buffer.OpenSection(reader.Quotas); bufferWriter.WriteStartElement(DummyName, DummyNamespace); } bufferWriter.WriteNode(reader, true); } // ServiceName reader.MoveToContent(); if (reader.IsStartElement(XD.AddressingDictionary.ServiceName, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace)) { if (bufferWriter == null) { if (buffer == null) { buffer = new XmlBuffer(short.MaxValue); } bufferWriter = buffer.OpenSection(reader.Quotas); bufferWriter.WriteStartElement(DummyName, DummyNamespace); } bufferWriter.WriteNode(reader, true); } // Policy reader.MoveToContent(); while (reader.IsNamespaceUri(XD.PolicyDictionary.Namespace)) { 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(); } // Finish PSP if (bufferWriter != null) { bufferWriter.WriteEndElement(); buffer.CloseSection(); pspSection = buffer.SectionCount - 1; bufferWriter = null; } else { pspSection = -1; } // Metadata if (reader.IsStartElement(Description.MetadataStrings.MetadataExchangeStrings.Metadata, Description.MetadataStrings.MetadataExchangeStrings.Namespace)) { if (bufferWriter == null) { if (buffer == null) { buffer = new XmlBuffer(short.MaxValue); } bufferWriter = buffer.OpenSection(reader.Quotas); bufferWriter.WriteStartElement(DummyName, DummyNamespace); } bufferWriter.WriteNode(reader, true); } // Finish metadata if (bufferWriter != null) { bufferWriter.WriteEndElement(); buffer.CloseSection(); metadataSection = buffer.SectionCount - 1; } else { metadataSection = -1; } // Extensions reader.MoveToContent(); buffer = ReadExtensions(reader, AddressingVersion.WSAddressingAugust2004, buffer, out identity, out extensionSection); // Finished reading if (buffer != null) { buffer.Close(); } // Process Address if (address == Addressing200408Strings.Anonymous) { uri = AddressingVersion.WSAddressingAugust2004.AnonymousUri; if (headers == null && identity == null) { return(true); } } else { if (!Uri.TryCreate(address, UriKind.Absolute, out uri)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.InvalidUriValue, address, XD.AddressingDictionary.Address.Value, AddressingVersion.WSAddressingAugust2004.Namespace))); } } return(false); }
private void Init(AddressingVersion version, Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlBuffer buffer, int metadataSection, int extensionSection, int pspSection) { if (!uri.IsAbsoluteUri) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(uri), SR.UriMustBeAbsolute); } _addressingVersion = version; Uri = uri; Identity = identity; _headers = headers; Buffer = buffer; _metadataSection = metadataSection; _extensionSection = extensionSection; _pspSection = pspSection; if (version != null) { IsAnonymous = uri == version.AnonymousUri; IsNone = uri == version.NoneUri; } else { IsAnonymous = ReferenceEquals(uri, AnonymousUri) || uri == AnonymousUri; IsNone = ReferenceEquals(uri, NoneUri) || uri == NoneUri; } if (IsAnonymous) { Uri = AnonymousUri; } if (IsNone) { Uri = NoneUri; } }