< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.EndpointAddressAugust2004
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/EndpointAddressAugust2004.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 41
Coverable lines: 41
Total lines: 224
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 20
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/EndpointAddressAugust2004.cs

#LineLine coverage
 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
 4using System.Collections;
 5using System.IO;
 6using System.Xml;
 7using System.Xml.Schema;
 8using System.Xml.Serialization;
 9using CoreWCF.Channels;
 10
 11namespace 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
 021        private EndpointAddressAugust2004()
 22        {
 023            _address = null;
 024        }
 25
 026        private EndpointAddressAugust2004(EndpointAddress address)
 27        {
 028            _address = address;
 029        }
 30
 31        public static EndpointAddressAugust2004 FromEndpointAddress(EndpointAddress address)
 32        {
 033            if (address == null)
 34            {
 035                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(address));
 36            }
 037            return new EndpointAddressAugust2004(address);
 38        }
 39
 40        public EndpointAddress ToEndpointAddress()
 41        {
 042            return _address;
 43        }
 44
 45        void IXmlSerializable.ReadXml(XmlReader reader)
 46        {
 047            _address = EndpointAddress.ReadFrom(AddressingVersion.WSAddressingAugust2004, XmlDictionaryReader.CreateDict
 048        }
 49
 50        void IXmlSerializable.WriteXml(XmlWriter writer)
 51        {
 052            _address.WriteContentsTo(AddressingVersion.WSAddressingAugust2004, XmlDictionaryWriter.CreateDictionaryWrite
 053        }
 54
 55        private static XmlQualifiedName EprType
 56        {
 57            get
 58            {
 059                if (s_eprType == null)
 60                {
 061                    s_eprType = new XmlQualifiedName(AddressingStrings.EndpointReferenceType, Addressing200408Strings.Na
 62                }
 63
 064                return s_eprType;
 65            }
 66        }
 67
 68        private static XmlSchema GetEprSchema()
 69        {
 070            using (XmlTextReader reader = new XmlTextReader(new StringReader(Schema)) { DtdProcessing = DtdProcessing.Pr
 71            {
 072                return XmlSchema.Read(reader, null);
 73            }
 074        }
 75
 76        public static XmlQualifiedName GetSchema(XmlSchemaSet xmlSchemaSet)
 77        {
 078            if (xmlSchemaSet == null)
 79            {
 080                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(xmlSchemaSet));
 81            }
 82
 083            XmlQualifiedName eprType = EprType;
 084            XmlSchema eprSchema = GetEprSchema();
 085            ICollection schemas = xmlSchemaSet.Schemas(Addressing200408Strings.Namespace);
 086            if (schemas == null || schemas.Count == 0)
 87            {
 088                xmlSchemaSet.Add(eprSchema);
 89            }
 90            else
 91            {
 092                XmlSchema schemaToAdd = null;
 093                foreach (XmlSchema xmlSchema in schemas)
 94                {
 095                    if (xmlSchema.SchemaTypes.Contains(eprType))
 96                    {
 097                        schemaToAdd = null;
 098                        break;
 99                    }
 100                    else
 101                    {
 0102                        schemaToAdd = xmlSchema;
 103                    }
 104                }
 0105                if (schemaToAdd != null)
 106                {
 0107                    foreach (XmlQualifiedName prefixNsPair in eprSchema.Namespaces.ToArray())
 108                    {
 0109                        schemaToAdd.Namespaces.Add(prefixNsPair.Name, prefixNsPair.Namespace);
 110                    }
 111
 0112                    foreach (XmlSchemaObject schemaObject in eprSchema.Items)
 113                    {
 0114                        schemaToAdd.Items.Add(schemaObject);
 115                    }
 116
 0117                    xmlSchemaSet.Reprocess(schemaToAdd);
 118                }
 119            }
 0120            return eprType;
 121        }
 122
 123        XmlSchema IXmlSerializable.GetSchema()
 124        {
 0125            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}