| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System.Collections; |
| | | 5 | | using System.IO; |
| | | 6 | | using System.Xml; |
| | | 7 | | using System.Xml.Schema; |
| | | 8 | | using System.Xml.Serialization; |
| | | 9 | | using CoreWCF.Channels; |
| | | 10 | | |
| | | 11 | | namespace CoreWCF |
| | | 12 | | { |
| | | 13 | | [XmlSchemaProvider("GetSchema")] |
| | | 14 | | [XmlRoot(AddressingStrings.EndpointReference, Namespace = Addressing10Strings.Namespace)] |
| | | 15 | | public class EndpointAddress10 : IXmlSerializable |
| | | 16 | | { |
| | | 17 | | private static XmlQualifiedName s_eprType; |
| | | 18 | | private EndpointAddress _address; |
| | | 19 | | |
| | | 20 | | // for IXmlSerializable |
| | 0 | 21 | | private EndpointAddress10() |
| | | 22 | | { |
| | 0 | 23 | | _address = null; |
| | 0 | 24 | | } |
| | | 25 | | |
| | 0 | 26 | | private EndpointAddress10(EndpointAddress address) |
| | | 27 | | { |
| | 0 | 28 | | _address = address; |
| | 0 | 29 | | } |
| | | 30 | | |
| | | 31 | | public static EndpointAddress10 FromEndpointAddress(EndpointAddress address) |
| | | 32 | | { |
| | 0 | 33 | | if (address == null) |
| | | 34 | | { |
| | 0 | 35 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(address)); |
| | | 36 | | } |
| | 0 | 37 | | return new EndpointAddress10(address); |
| | | 38 | | } |
| | | 39 | | |
| | | 40 | | public EndpointAddress ToEndpointAddress() |
| | | 41 | | { |
| | 0 | 42 | | return _address; |
| | | 43 | | } |
| | | 44 | | |
| | | 45 | | void IXmlSerializable.ReadXml(XmlReader reader) |
| | | 46 | | { |
| | 0 | 47 | | _address = EndpointAddress.ReadFrom(AddressingVersion.WSAddressing10, XmlDictionaryReader.CreateDictionaryRe |
| | 0 | 48 | | } |
| | | 49 | | |
| | | 50 | | void IXmlSerializable.WriteXml(XmlWriter writer) |
| | | 51 | | { |
| | 0 | 52 | | _address.WriteContentsTo(AddressingVersion.WSAddressing10, XmlDictionaryWriter.CreateDictionaryWriter(writer |
| | 0 | 53 | | } |
| | | 54 | | |
| | | 55 | | private static XmlQualifiedName EprType |
| | | 56 | | { |
| | | 57 | | get |
| | | 58 | | { |
| | 0 | 59 | | if (s_eprType == null) |
| | | 60 | | { |
| | 0 | 61 | | s_eprType = new XmlQualifiedName(AddressingStrings.EndpointReferenceType, Addressing10Strings.Namesp |
| | | 62 | | } |
| | | 63 | | |
| | 0 | 64 | | return s_eprType; |
| | | 65 | | } |
| | | 66 | | } |
| | | 67 | | |
| | | 68 | | private static XmlSchema GetEprSchema() |
| | | 69 | | { |
| | 0 | 70 | | using (XmlTextReader reader = new XmlTextReader(new StringReader(Schema)) { DtdProcessing = DtdProcessing.Pr |
| | | 71 | | { |
| | 0 | 72 | | return XmlSchema.Read(reader, null); |
| | | 73 | | } |
| | 0 | 74 | | } |
| | | 75 | | |
| | | 76 | | public static XmlQualifiedName GetSchema(XmlSchemaSet xmlSchemaSet) |
| | | 77 | | { |
| | 0 | 78 | | if (xmlSchemaSet == null) |
| | | 79 | | { |
| | 0 | 80 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(xmlSchemaSet)); |
| | | 81 | | } |
| | | 82 | | |
| | 0 | 83 | | XmlQualifiedName eprType = EprType; |
| | 0 | 84 | | XmlSchema eprSchema = GetEprSchema(); |
| | 0 | 85 | | ICollection schemas = xmlSchemaSet.Schemas(Addressing10Strings.Namespace); |
| | 0 | 86 | | if (schemas == null || schemas.Count == 0) |
| | | 87 | | { |
| | 0 | 88 | | xmlSchemaSet.Add(eprSchema); |
| | | 89 | | } |
| | | 90 | | else |
| | | 91 | | { |
| | 0 | 92 | | XmlSchema schemaToAdd = null; |
| | 0 | 93 | | foreach (XmlSchema xmlSchema in schemas) |
| | | 94 | | { |
| | 0 | 95 | | if (xmlSchema.SchemaTypes.Contains(eprType)) |
| | | 96 | | { |
| | 0 | 97 | | schemaToAdd = null; |
| | 0 | 98 | | break; |
| | | 99 | | } |
| | | 100 | | else |
| | | 101 | | { |
| | 0 | 102 | | schemaToAdd = xmlSchema; |
| | | 103 | | } |
| | | 104 | | } |
| | 0 | 105 | | if (schemaToAdd != null) |
| | | 106 | | { |
| | 0 | 107 | | foreach (XmlQualifiedName prefixNsPair in eprSchema.Namespaces.ToArray()) |
| | | 108 | | { |
| | 0 | 109 | | schemaToAdd.Namespaces.Add(prefixNsPair.Name, prefixNsPair.Namespace); |
| | | 110 | | } |
| | | 111 | | |
| | 0 | 112 | | foreach (XmlSchemaObject schemaObject in eprSchema.Items) |
| | | 113 | | { |
| | 0 | 114 | | schemaToAdd.Items.Add(schemaObject); |
| | | 115 | | } |
| | | 116 | | |
| | 0 | 117 | | xmlSchemaSet.Reprocess(schemaToAdd); |
| | | 118 | | } |
| | | 119 | | } |
| | 0 | 120 | | return eprType; |
| | | 121 | | } |
| | | 122 | | |
| | | 123 | | XmlSchema IXmlSerializable.GetSchema() |
| | | 124 | | { |
| | 0 | 125 | | return null; |
| | | 126 | | } |
| | | 127 | | |
| | | 128 | | private const string Schema = |
| | | 129 | | @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' xmlns:wsa='http://www.w3.org/2005/08/addressing' targetNamespac |
| | | 130 | | |
| | | 131 | | <!-- Constructs from the WS-Addressing Core --> |
| | | 132 | | |
| | | 133 | | <xs:element name='EndpointReference' type='wsa:EndpointReferenceType'/> |
| | | 134 | | <xs:complexType name='EndpointReferenceType' mixed='false'> |
| | | 135 | | <xs:sequence> |
| | | 136 | | <xs:element name='Address' type='wsa:AttributedURIType'/> |
| | | 137 | | <xs:element name='ReferenceParameters' type='wsa:ReferenceParametersType' minOccurs='0'/> |
| | | 138 | | <xs:element ref='wsa:Metadata' minOccurs='0'/> |
| | | 139 | | <xs:any namespace='##other' processContents='lax' minOccurs='0' maxOccurs='unbounded'/> |
| | | 140 | | </xs:sequence> |
| | | 141 | | <xs:anyAttribute namespace='##other' processContents='lax'/> |
| | | 142 | | </xs:complexType> |
| | | 143 | | |
| | | 144 | | <xs:complexType name='ReferenceParametersType' mixed='false'> |
| | | 145 | | <xs:sequence> |
| | | 146 | | <xs:any namespace='##any' processContents='lax' minOccurs='0' maxOccurs='unbounded'/> |
| | | 147 | | </xs:sequence> |
| | | 148 | | <xs:anyAttribute namespace='##other' processContents='lax'/> |
| | | 149 | | </xs:complexType> |
| | | 150 | | |
| | | 151 | | <xs:element name='Metadata' type='wsa:MetadataType'/> |
| | | 152 | | <xs:complexType name='MetadataType' mixed='false'> |
| | | 153 | | <xs:sequence> |
| | | 154 | | <xs:any namespace='##any' processContents='lax' minOccurs='0' maxOccurs='unbounded'/> |
| | | 155 | | </xs:sequence> |
| | | 156 | | <xs:anyAttribute namespace='##other' processContents='lax'/> |
| | | 157 | | </xs:complexType> |
| | | 158 | | |
| | | 159 | | <xs:element name='MessageID' type='wsa:AttributedURIType'/> |
| | | 160 | | <xs:element name='RelatesTo' type='wsa:RelatesToType'/> |
| | | 161 | | <xs:complexType name='RelatesToType' mixed='false'> |
| | | 162 | | <xs:simpleContent> |
| | | 163 | | <xs:extension base='xs:anyURI'> |
| | | 164 | | <xs:attribute name='RelationshipType' type='wsa:RelationshipTypeOpenEnum' use='optional' default='http:/ |
| | | 165 | | <xs:anyAttribute namespace='##other' processContents='lax'/> |
| | | 166 | | </xs:extension> |
| | | 167 | | </xs:simpleContent> |
| | | 168 | | </xs:complexType> |
| | | 169 | | |
| | | 170 | | <xs:simpleType name='RelationshipTypeOpenEnum'> |
| | | 171 | | <xs:union memberTypes='wsa:RelationshipType xs:anyURI'/> |
| | | 172 | | </xs:simpleType> |
| | | 173 | | |
| | | 174 | | <xs:simpleType name='RelationshipType'> |
| | | 175 | | <xs:restriction base='xs:anyURI'> |
| | | 176 | | <xs:enumeration value='http://www.w3.org/2005/08/addressing/reply'/> |
| | | 177 | | </xs:restriction> |
| | | 178 | | </xs:simpleType> |
| | | 179 | | |
| | | 180 | | <xs:element name='ReplyTo' type='wsa:EndpointReferenceType'/> |
| | | 181 | | <xs:element name='From' type='wsa:EndpointReferenceType'/> |
| | | 182 | | <xs:element name='FaultTo' type='wsa:EndpointReferenceType'/> |
| | | 183 | | <xs:element name='To' type='wsa:AttributedURIType'/> |
| | | 184 | | <xs:element name='Action' type='wsa:AttributedURIType'/> |
| | | 185 | | |
| | | 186 | | <xs:complexType name='AttributedURIType' mixed='false'> |
| | | 187 | | <xs:simpleContent> |
| | | 188 | | <xs:extension base='xs:anyURI'> |
| | | 189 | | <xs:anyAttribute namespace='##other' processContents='lax'/> |
| | | 190 | | </xs:extension> |
| | | 191 | | </xs:simpleContent> |
| | | 192 | | </xs:complexType> |
| | | 193 | | |
| | | 194 | | <!-- Constructs from the WS-Addressing SOAP binding --> |
| | | 195 | | |
| | | 196 | | <xs:attribute name='IsReferenceParameter' type='xs:boolean'/> |
| | | 197 | | |
| | | 198 | | <xs:simpleType name='FaultCodesOpenEnumType'> |
| | | 199 | | <xs:union memberTypes='wsa:FaultCodesType xs:QName'/> |
| | | 200 | | </xs:simpleType> |
| | | 201 | | |
| | | 202 | | <xs:simpleType name='FaultCodesType'> |
| | | 203 | | <xs:restriction base='xs:QName'> |
| | | 204 | | <xs:enumeration value='wsa:InvalidAddressingHeader'/> |
| | | 205 | | <xs:enumeration value='wsa:InvalidAddress'/> |
| | | 206 | | <xs:enumeration value='wsa:InvalidEPR'/> |
| | | 207 | | <xs:enumeration value='wsa:InvalidCardinality'/> |
| | | 208 | | <xs:enumeration value='wsa:MissingAddressInEPR'/> |
| | | 209 | | <xs:enumeration value='wsa:DuplicateMessageID'/> |
| | | 210 | | <xs:enumeration value='wsa:ActionMismatch'/> |
| | | 211 | | <xs:enumeration value='wsa:MessageAddressingHeaderRequired'/> |
| | | 212 | | <xs:enumeration value='wsa:DestinationUnreachable'/> |
| | | 213 | | <xs:enumeration value='wsa:ActionNotSupported'/> |
| | | 214 | | <xs:enumeration value='wsa:EndpointUnavailable'/> |
| | | 215 | | </xs:restriction> |
| | | 216 | | </xs:simpleType> |
| | | 217 | | |
| | | 218 | | <xs:element name='RetryAfter' type='wsa:AttributedUnsignedLongType'/> |
| | | 219 | | <xs:complexType name='AttributedUnsignedLongType' mixed='false'> |
| | | 220 | | <xs:simpleContent> |
| | | 221 | | <xs:extension base='xs:unsignedLong'> |
| | | 222 | | <xs:anyAttribute namespace='##other' processContents='lax'/> |
| | | 223 | | </xs:extension> |
| | | 224 | | </xs:simpleContent> |
| | | 225 | | </xs:complexType> |
| | | 226 | | |
| | | 227 | | <xs:element name='ProblemHeaderQName' type='wsa:AttributedQNameType'/> |
| | | 228 | | <xs:complexType name='AttributedQNameType' mixed='false'> |
| | | 229 | | <xs:simpleContent> |
| | | 230 | | <xs:extension base='xs:QName'> |
| | | 231 | | <xs:anyAttribute namespace='##other' processContents='lax'/> |
| | | 232 | | </xs:extension> |
| | | 233 | | </xs:simpleContent> |
| | | 234 | | </xs:complexType> |
| | | 235 | | |
| | | 236 | | <xs:element name='ProblemHeader' type='wsa:AttributedAnyType'/> |
| | | 237 | | <xs:complexType name='AttributedAnyType' mixed='false'> |
| | | 238 | | <xs:sequence> |
| | | 239 | | <xs:any namespace='##any' processContents='lax' minOccurs='1' maxOccurs='1'/> |
| | | 240 | | </xs:sequence> |
| | | 241 | | <xs:anyAttribute namespace='##other' processContents='lax'/> |
| | | 242 | | </xs:complexType> |
| | | 243 | | |
| | | 244 | | <xs:element name='ProblemIRI' type='wsa:AttributedURIType'/> |
| | | 245 | | |
| | | 246 | | <xs:element name='ProblemAction' type='wsa:ProblemActionType'/> |
| | | 247 | | <xs:complexType name='ProblemActionType' mixed='false'> |
| | | 248 | | <xs:sequence> |
| | | 249 | | <xs:element ref='wsa:Action' minOccurs='0'/> |
| | | 250 | | <xs:element name='SoapAction' minOccurs='0' type='xs:anyURI'/> |
| | | 251 | | </xs:sequence> |
| | | 252 | | <xs:anyAttribute namespace='##other' processContents='lax'/> |
| | | 253 | | </xs:complexType> |
| | | 254 | | |
| | | 255 | | </xs:schema>"; |
| | | 256 | | } |
| | | 257 | | } |