1 //-----------------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //-----------------------------------------------------------------------------
4 namespace System.ServiceModel
7 using System.ServiceModel.Channels;
9 using System.Xml.Schema;
10 using System.Xml.Serialization;
11 using System.Collections;
15 [XmlSchemaProvider("GetSchema")]
16 [XmlRoot(AddressingStrings.EndpointReference, Namespace = Addressing10Strings.Namespace)]
17 public class EndpointAddress10 : IXmlSerializable
19 static XmlQualifiedName eprType;
21 EndpointAddress address;
23 // for IXmlSerializable
29 EndpointAddress10(EndpointAddress address)
31 this.address = address;
34 public static EndpointAddress10 FromEndpointAddress(EndpointAddress address)
38 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("address");
40 return new EndpointAddress10(address);
43 public EndpointAddress ToEndpointAddress()
48 void IXmlSerializable.ReadXml(XmlReader reader)
50 this.address = EndpointAddress.ReadFrom(AddressingVersion.WSAddressing10, XmlDictionaryReader.CreateDictionaryReader(reader));
53 void IXmlSerializable.WriteXml(XmlWriter writer)
55 this.address.WriteContentsTo(AddressingVersion.WSAddressing10, XmlDictionaryWriter.CreateDictionaryWriter(writer));
58 static XmlQualifiedName EprType
63 eprType = new XmlQualifiedName(AddressingStrings.EndpointReferenceType, Addressing10Strings.Namespace);
68 static XmlSchema GetEprSchema()
70 using (XmlTextReader reader = new XmlTextReader(new StringReader(Schema)) { DtdProcessing = DtdProcessing.Prohibit })
72 return XmlSchema.Read(reader, null);
77 public static XmlQualifiedName GetSchema(XmlSchemaSet xmlSchemaSet)
79 if (xmlSchemaSet == null)
80 throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("xmlSchemaSet");
81 XmlQualifiedName eprType = EprType;
82 XmlSchema eprSchema = GetEprSchema();
83 ICollection schemas = xmlSchemaSet.Schemas(Addressing10Strings.Namespace);
84 if (schemas == null || schemas.Count == 0)
85 xmlSchemaSet.Add(eprSchema);
88 XmlSchema schemaToAdd = null;
89 foreach (XmlSchema xmlSchema in schemas)
91 if (xmlSchema.SchemaTypes.Contains(eprType))
97 schemaToAdd = xmlSchema;
99 if (schemaToAdd != null)
101 foreach (XmlQualifiedName prefixNsPair in eprSchema.Namespaces.ToArray())
102 schemaToAdd.Namespaces.Add(prefixNsPair.Name, prefixNsPair.Namespace);
103 foreach (XmlSchemaObject schemaObject in eprSchema.Items)
104 schemaToAdd.Items.Add(schemaObject);
105 xmlSchemaSet.Reprocess(schemaToAdd);
111 XmlSchema IXmlSerializable.GetSchema()
116 const string Schema =
117 @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:wsa='http://www.w3.org/2005/08/addressing' targetNamespace='http://www.w3.org/2005/08/addressing' blockDefault='#all' elementFormDefault='qualified' finalDefault='' attributeFormDefault='unqualified'>
119 <!-- Constructs from the WS-Addressing Core -->
121 <xs:element name='EndpointReference' type='wsa:EndpointReferenceType'/>
122 <xs:complexType name='EndpointReferenceType' mixed='false'>
124 <xs:element name='Address' type='wsa:AttributedURIType'/>
125 <xs:element name='ReferenceParameters' type='wsa:ReferenceParametersType' minOccurs='0'/>
126 <xs:element ref='wsa:Metadata' minOccurs='0'/>
127 <xs:any namespace='##other' processContents='lax' minOccurs='0' maxOccurs='unbounded'/>
129 <xs:anyAttribute namespace='##other' processContents='lax'/>
132 <xs:complexType name='ReferenceParametersType' mixed='false'>
134 <xs:any namespace='##any' processContents='lax' minOccurs='0' maxOccurs='unbounded'/>
136 <xs:anyAttribute namespace='##other' processContents='lax'/>
139 <xs:element name='Metadata' type='wsa:MetadataType'/>
140 <xs:complexType name='MetadataType' mixed='false'>
142 <xs:any namespace='##any' processContents='lax' minOccurs='0' maxOccurs='unbounded'/>
144 <xs:anyAttribute namespace='##other' processContents='lax'/>
147 <xs:element name='MessageID' type='wsa:AttributedURIType'/>
148 <xs:element name='RelatesTo' type='wsa:RelatesToType'/>
149 <xs:complexType name='RelatesToType' mixed='false'>
151 <xs:extension base='xs:anyURI'>
152 <xs:attribute name='RelationshipType' type='wsa:RelationshipTypeOpenEnum' use='optional' default='http://www.w3.org/2005/08/addressing/reply'/>
153 <xs:anyAttribute namespace='##other' processContents='lax'/>
158 <xs:simpleType name='RelationshipTypeOpenEnum'>
159 <xs:union memberTypes='wsa:RelationshipType xs:anyURI'/>
162 <xs:simpleType name='RelationshipType'>
163 <xs:restriction base='xs:anyURI'>
164 <xs:enumeration value='http://www.w3.org/2005/08/addressing/reply'/>
168 <xs:element name='ReplyTo' type='wsa:EndpointReferenceType'/>
169 <xs:element name='From' type='wsa:EndpointReferenceType'/>
170 <xs:element name='FaultTo' type='wsa:EndpointReferenceType'/>
171 <xs:element name='To' type='wsa:AttributedURIType'/>
172 <xs:element name='Action' type='wsa:AttributedURIType'/>
174 <xs:complexType name='AttributedURIType' mixed='false'>
176 <xs:extension base='xs:anyURI'>
177 <xs:anyAttribute namespace='##other' processContents='lax'/>
182 <!-- Constructs from the WS-Addressing SOAP binding -->
184 <xs:attribute name='IsReferenceParameter' type='xs:boolean'/>
186 <xs:simpleType name='FaultCodesOpenEnumType'>
187 <xs:union memberTypes='wsa:FaultCodesType xs:QName'/>
190 <xs:simpleType name='FaultCodesType'>
191 <xs:restriction base='xs:QName'>
192 <xs:enumeration value='wsa:InvalidAddressingHeader'/>
193 <xs:enumeration value='wsa:InvalidAddress'/>
194 <xs:enumeration value='wsa:InvalidEPR'/>
195 <xs:enumeration value='wsa:InvalidCardinality'/>
196 <xs:enumeration value='wsa:MissingAddressInEPR'/>
197 <xs:enumeration value='wsa:DuplicateMessageID'/>
198 <xs:enumeration value='wsa:ActionMismatch'/>
199 <xs:enumeration value='wsa:MessageAddressingHeaderRequired'/>
200 <xs:enumeration value='wsa:DestinationUnreachable'/>
201 <xs:enumeration value='wsa:ActionNotSupported'/>
202 <xs:enumeration value='wsa:EndpointUnavailable'/>
206 <xs:element name='RetryAfter' type='wsa:AttributedUnsignedLongType'/>
207 <xs:complexType name='AttributedUnsignedLongType' mixed='false'>
209 <xs:extension base='xs:unsignedLong'>
210 <xs:anyAttribute namespace='##other' processContents='lax'/>
215 <xs:element name='ProblemHeaderQName' type='wsa:AttributedQNameType'/>
216 <xs:complexType name='AttributedQNameType' mixed='false'>
218 <xs:extension base='xs:QName'>
219 <xs:anyAttribute namespace='##other' processContents='lax'/>
224 <xs:element name='ProblemHeader' type='wsa:AttributedAnyType'/>
225 <xs:complexType name='AttributedAnyType' mixed='false'>
227 <xs:any namespace='##any' processContents='lax' minOccurs='1' maxOccurs='1'/>
229 <xs:anyAttribute namespace='##other' processContents='lax'/>
232 <xs:element name='ProblemIRI' type='wsa:AttributedURIType'/>
234 <xs:element name='ProblemAction' type='wsa:ProblemActionType'/>
235 <xs:complexType name='ProblemActionType' mixed='false'>
237 <xs:element ref='wsa:Action' minOccurs='0'/>
238 <xs:element name='SoapAction' minOccurs='0' type='xs:anyURI'/>
240 <xs:anyAttribute namespace='##other' processContents='lax'/>