//----------------------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.ServiceModel { using System; using System.ServiceModel.Channels; using System.Xml; using System.Xml.Schema; using System.Xml.Serialization; using System.Collections; using System.Text; using System.IO; [XmlSchemaProvider("GetSchema")] [XmlRoot(AddressingStrings.EndpointReference, Namespace = Addressing10Strings.Namespace)] public class EndpointAddress10 : IXmlSerializable { static XmlQualifiedName eprType; EndpointAddress address; // for IXmlSerializable EndpointAddress10() { this.address = null; } EndpointAddress10(EndpointAddress address) { this.address = address; } public static EndpointAddress10 FromEndpointAddress(EndpointAddress address) { if (address == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("address"); } return new EndpointAddress10(address); } public EndpointAddress ToEndpointAddress() { return this.address; } void IXmlSerializable.ReadXml(XmlReader reader) { this.address = EndpointAddress.ReadFrom(AddressingVersion.WSAddressing10, XmlDictionaryReader.CreateDictionaryReader(reader)); } void IXmlSerializable.WriteXml(XmlWriter writer) { this.address.WriteContentsTo(AddressingVersion.WSAddressing10, XmlDictionaryWriter.CreateDictionaryWriter(writer)); } static XmlQualifiedName EprType { get { if (eprType == null) eprType = new XmlQualifiedName(AddressingStrings.EndpointReferenceType, Addressing10Strings.Namespace); return eprType; } } static XmlSchema GetEprSchema() { using (XmlTextReader reader = new XmlTextReader(new StringReader(Schema))) { return XmlSchema.Read(reader, null); } } public static XmlQualifiedName GetSchema(XmlSchemaSet xmlSchemaSet) { if (xmlSchemaSet == null) throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("xmlSchemaSet"); XmlQualifiedName eprType = EprType; XmlSchema eprSchema = GetEprSchema(); ICollection schemas = xmlSchemaSet.Schemas(Addressing10Strings.Namespace); if (schemas == null || schemas.Count == 0) xmlSchemaSet.Add(eprSchema); else { XmlSchema schemaToAdd = null; foreach (XmlSchema xmlSchema in schemas) { if (xmlSchema.SchemaTypes.Contains(eprType)) { schemaToAdd = null; break; } else schemaToAdd = xmlSchema; } if (schemaToAdd != null) { foreach (XmlQualifiedName prefixNsPair in eprSchema.Namespaces.ToArray()) schemaToAdd.Namespaces.Add(prefixNsPair.Name, prefixNsPair.Namespace); foreach (XmlSchemaObject schemaObject in eprSchema.Items) schemaToAdd.Items.Add(schemaObject); xmlSchemaSet.Reprocess(schemaToAdd); } } return eprType; } XmlSchema IXmlSerializable.GetSchema() { return null; } const string Schema = @" "; } }