| | | 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 = Addressing200408Strings.Namespace)] |
| | | 15 | | public class EndpointAddressAugust2004 : IXmlSerializable |
| | | 16 | | { |
| | | 17 | | private static XmlQualifiedName s_eprType; |
| | | 18 | | private EndpointAddress _address; |
| | | 19 | | |
| | | 20 | | // for IXmlSerializable |
| | 0 | 21 | | private EndpointAddressAugust2004() |
| | | 22 | | { |
| | 0 | 23 | | _address = null; |
| | 0 | 24 | | } |
| | | 25 | | |
| | 0 | 26 | | private EndpointAddressAugust2004(EndpointAddress address) |
| | | 27 | | { |
| | 0 | 28 | | _address = address; |
| | 0 | 29 | | } |
| | | 30 | | |
| | | 31 | | public static EndpointAddressAugust2004 FromEndpointAddress(EndpointAddress address) |
| | | 32 | | { |
| | 0 | 33 | | if (address == null) |
| | | 34 | | { |
| | 0 | 35 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(address)); |
| | | 36 | | } |
| | 0 | 37 | | return new EndpointAddressAugust2004(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.WSAddressingAugust2004, XmlDictionaryReader.CreateDict |
| | 0 | 48 | | } |
| | | 49 | | |
| | | 50 | | void IXmlSerializable.WriteXml(XmlWriter writer) |
| | | 51 | | { |
| | 0 | 52 | | _address.WriteContentsTo(AddressingVersion.WSAddressingAugust2004, XmlDictionaryWriter.CreateDictionaryWrite |
| | 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, Addressing200408Strings.Na |
| | | 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(Addressing200408Strings.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 targetNamespace=""http://schemas.xmlsoap.org/ws/2004/08/addressing"" xmlns:xs=""http://www.w3.org/2001/XMLS |
| | | 130 | | <!-- //////////////////// WS-Addressing //////////////////// --> |
| | | 131 | | <!-- Endpoint reference --> |
| | | 132 | | <xs:element name=""EndpointReference"" type=""wsa:EndpointReferenceType""/> |
| | | 133 | | <xs:complexType name=""EndpointReferenceType""> |
| | | 134 | | <xs:sequence> |
| | | 135 | | <xs:element name=""Address"" type=""wsa:AttributedURI""/> |
| | | 136 | | <xs:element name=""ReferenceProperties"" type=""wsa:ReferencePropertiesType"" minOccurs=""0""/> |
| | | 137 | | <xs:element name=""ReferenceParameters"" type=""wsa:ReferenceParametersType"" minOccurs=""0""/> |
| | | 138 | | <xs:element name=""PortType"" type=""wsa:AttributedQName"" minOccurs=""0""/> |
| | | 139 | | <xs:element name=""ServiceName"" type=""wsa:ServiceNameType"" minOccurs=""0""/> |
| | | 140 | | <xs:any namespace=""##other"" processContents=""lax"" minOccurs=""0"" maxOccurs=""unbounded""> |
| | | 141 | | <xs:annotation> |
| | | 142 | | <xs:documentation> |
| | | 143 | | If ""Policy"" elements from namespace ""http://schemas.xmlsoap.org/ws/2002/12/policy#policy"" are used, they |
| | | 144 | | </xs:documentation> |
| | | 145 | | </xs:annotation> |
| | | 146 | | </xs:any> |
| | | 147 | | </xs:sequence> |
| | | 148 | | <xs:anyAttribute namespace=""##other"" processContents=""lax""/> |
| | | 149 | | </xs:complexType> |
| | | 150 | | <xs:complexType name=""ReferencePropertiesType""> |
| | | 151 | | <xs:sequence> |
| | | 152 | | <xs:any processContents=""lax"" minOccurs=""0"" maxOccurs=""unbounded""/> |
| | | 153 | | </xs:sequence> |
| | | 154 | | </xs:complexType> |
| | | 155 | | <xs:complexType name=""ReferenceParametersType""> |
| | | 156 | | <xs:sequence> |
| | | 157 | | <xs:any processContents=""lax"" minOccurs=""0"" maxOccurs=""unbounded""/> |
| | | 158 | | </xs:sequence> |
| | | 159 | | </xs:complexType> |
| | | 160 | | <xs:complexType name=""ServiceNameType""> |
| | | 161 | | <xs:simpleContent> |
| | | 162 | | <xs:extension base=""xs:QName""> |
| | | 163 | | <xs:attribute name=""PortName"" type=""xs:NCName""/> |
| | | 164 | | <xs:anyAttribute namespace=""##other"" processContents=""lax""/> |
| | | 165 | | </xs:extension> |
| | | 166 | | </xs:simpleContent> |
| | | 167 | | </xs:complexType> |
| | | 168 | | <!-- Message information header blocks --> |
| | | 169 | | <xs:element name=""MessageID"" type=""wsa:AttributedURI""/> |
| | | 170 | | <xs:element name=""RelatesTo"" type=""wsa:Relationship""/> |
| | | 171 | | <xs:element name=""To"" type=""wsa:AttributedURI""/> |
| | | 172 | | <xs:element name=""Action"" type=""wsa:AttributedURI""/> |
| | | 173 | | <xs:element name=""From"" type=""wsa:EndpointReferenceType""/> |
| | | 174 | | <xs:element name=""ReplyTo"" type=""wsa:EndpointReferenceType""/> |
| | | 175 | | <xs:element name=""FaultTo"" type=""wsa:EndpointReferenceType""/> |
| | | 176 | | <xs:complexType name=""Relationship""> |
| | | 177 | | <xs:simpleContent> |
| | | 178 | | <xs:extension base=""xs:anyURI""> |
| | | 179 | | <xs:attribute name=""RelationshipType"" type=""xs:QName"" use=""optional""/> |
| | | 180 | | <xs:anyAttribute namespace=""##other"" processContents=""lax""/> |
| | | 181 | | </xs:extension> |
| | | 182 | | </xs:simpleContent> |
| | | 183 | | </xs:complexType> |
| | | 184 | | <xs:simpleType name=""RelationshipTypeValues""> |
| | | 185 | | <xs:restriction base=""xs:QName""> |
| | | 186 | | <xs:enumeration value=""wsa:Reply""/> |
| | | 187 | | </xs:restriction> |
| | | 188 | | </xs:simpleType> |
| | | 189 | | <xs:element name=""ReplyAfter"" type=""wsa:ReplyAfterType""/> |
| | | 190 | | <xs:complexType name=""ReplyAfterType""> |
| | | 191 | | <xs:simpleContent> |
| | | 192 | | <xs:extension base=""xs:nonNegativeInteger""> |
| | | 193 | | <xs:anyAttribute namespace=""##other""/> |
| | | 194 | | </xs:extension> |
| | | 195 | | </xs:simpleContent> |
| | | 196 | | </xs:complexType> |
| | | 197 | | <xs:simpleType name=""FaultSubcodeValues""> |
| | | 198 | | <xs:restriction base=""xs:QName""> |
| | | 199 | | <xs:enumeration value=""wsa:InvalidMessageInformationHeader""/> |
| | | 200 | | <xs:enumeration value=""wsa:MessageInformationHeaderRequired""/> |
| | | 201 | | <xs:enumeration value=""wsa:DestinationUnreachable""/> |
| | | 202 | | <xs:enumeration value=""wsa:ActionNotSupported""/> |
| | | 203 | | <xs:enumeration value=""wsa:EndpointUnavailable""/> |
| | | 204 | | </xs:restriction> |
| | | 205 | | </xs:simpleType> |
| | | 206 | | <xs:attribute name=""Action"" type=""xs:anyURI""/> |
| | | 207 | | <!-- Common declarations and definitions --> |
| | | 208 | | <xs:complexType name=""AttributedQName""> |
| | | 209 | | <xs:simpleContent> |
| | | 210 | | <xs:extension base=""xs:QName""> |
| | | 211 | | <xs:anyAttribute namespace=""##other"" processContents=""lax""/> |
| | | 212 | | </xs:extension> |
| | | 213 | | </xs:simpleContent> |
| | | 214 | | </xs:complexType> |
| | | 215 | | <xs:complexType name=""AttributedURI""> |
| | | 216 | | <xs:simpleContent> |
| | | 217 | | <xs:extension base=""xs:anyURI""> |
| | | 218 | | <xs:anyAttribute namespace=""##other"" processContents=""lax""/> |
| | | 219 | | </xs:extension> |
| | | 220 | | </xs:simpleContent> |
| | | 221 | | </xs:complexType> |
| | | 222 | | </xs:schema>"; |
| | | 223 | | } |
| | | 224 | | } |