< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.EndpointAddress
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/EndpointAddress.cs
Line coverage
47%
Covered lines: 222
Uncovered lines: 242
Coverable lines: 464
Total lines: 1337
Line coverage: 47.8%
Branch coverage
43%
Covered branches: 134
Total branches: 308
Branch coverage: 43.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
.ctor(...)50%2283.33%
.ctor(...)100%11100%
.ctor(...)50%2280%
.ctor(...)100%110%
.ctor(...)0%10100%
.ctor(...)100%110%
Init(...)75%4450%
Init(...)100%11100%
Init(...)83.33%121285%
ApplyTo(...)70%101073.33%
UriEquals(...)100%11100%
UriEquals(...)40%303045%
UriGetHashCode(...)100%11100%
UriGetHashCode(...)100%88100%
EndpointEquals(...)50%141456.25%
Equals(...)66.66%6675%
GetHashCode()100%11100%
GetReaderAtPsp()100%110%
GetReaderAtMetadata()100%110%
GetReaderAtExtensions()100%110%
GetReaderAtSection(...)0%440%
PossiblyPopulateBuffer(...)0%440%
ReadFrom(...)100%110%
ReadFrom(...)0%880%
ReadFrom(...)0%880%
ReadFrom(...)50%4475%
ReadFromDriver(...)58.33%121270%
ReadExtensions(...)16.66%181829.62%
ReadContentsFrom200408(...)26%505040.5%
ReadContentsFrom10(...)31.81%222242.42%
CreateXmlException(...)0%220%
Done(...)0%220%
Copy(...)0%220%
ToString()100%110%
WriteContentsTo(...)70%101066.66%
WriteContentsToNone(...)100%11100%
WriteContentsTo10(...)55.55%181848%
WriteContentsTo200408(...)62.5%242450%
WriteContentsTo(...)100%11100%
WriteTo(...)50%8866.66%
WriteTo(...)50%2283.33%
op_Equality(...)100%22100%
op_Inequality(...)50%2266.66%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/EndpointAddress.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;
 5using System.Collections.Generic;
 6using System.Collections.ObjectModel;
 7using System.Xml;
 8using CoreWCF.Channels;
 9using CoreWCF.Runtime;
 10
 11namespace CoreWCF
 12{
 13    public class EndpointAddress
 14    {
 15        private static Uri s_anonymousUri;
 16        private static Uri s_noneUri;
 17        private static EndpointAddress s_anonymousAddress;
 18
 19        /*
 20        Conceptually, the agnostic EndpointAddress class represents all of UNION(v200408,v10) data thusly:
 21         - Address Uri (both versions - the Address)
 22         - AddressHeaderCollection (both versions - RefProp&RefParam both project into here)
 23         - PSP blob (200408 - this is PortType, ServiceName, Policy, it is not surfaced in OM)
 24         - metadata (both versions, but weird semantics in 200408)
 25         - identity (both versions, this is the one 'extension' that we know about)
 26         - extensions (both versions, the "any*" stuff at the end)
 27
 28        When reading from 200408:
 29         - Address is projected into Uri
 30         - both RefProps and RefParams are projected into AddressHeaderCollection,
 31              they (internally) remember 'which kind' they are
 32         - PortType, ServiceName, Policy are projected into the (internal) PSP blob
 33         - if we see a wsx:metadata element next, we project that element and that element only into the metadata reader
 34         - we read the rest, recognizing and fishing out identity if there, projecting rest to extensions reader
 35        When reading from 10:
 36         - Address is projected into Uri
 37         - RefParams are projected into AddressHeaderCollection; they (internally) remember 'which kind' they are
 38         - nothing is projected into the (internal) PSP blob (it's empty)
 39         - if there's a wsa10:metadata element, everything inside it projects into metadatareader
 40         - we read the rest, recognizing and fishing out identity if there, projecting rest to extensions reader
 41
 42        When writing to 200408:
 43         - Uri is written as Address
 44         - AddressHeaderCollection is written as RefProps & RefParams, based on what they internally remember selves to 
 45         - PSP blob is written out verbatim (will have: PortType?, ServiceName?, Policy?)
 46         - metadata reader is written out verbatim
 47         - identity is written out as extension
 48         - extension reader is written out verbatim
 49        When writing to 10:
 50         - Uri is written as Address
 51         - AddressHeaderCollection is all written as RefParams, regardless of what they internally remember selves to be
 52         - PSP blob is ignored
 53         - if metadata reader is non-empty, we write its value out verbatim inside a wsa10:metadata element
 54         - identity is written out as extension
 55         - extension reader is written out verbatim
 56
 57        EndpointAddressBuilder:
 58         - you can set metadata to any value you like; we don't (cannot) validate because 10 allows anything
 59         - you can set any extensions you like
 60
 61        Known Weirdnesses:
 62         - PSP blob does not surface in OM - it can only roundtrip 200408wire->OM->200408wire
 63         - RefProperty distinction does not surface in OM - it can only roundtrip 200408wire->OM->200408wire
 64         - regardless of what metadata in reader, when you roundtrip OM->200408wire->OM, only wsx:metadata
 65               as first element after PSP will stay in metadata, anything else gets dumped in extensions
 66         - PSP blob is lost when doing OM->10wire->OM
 67         - RefProps turn into RefParams when doing OM->10wire->OM
 68         - Identity is always shuffled to front of extensions when doing anyWire->OM->anyWire
 69        */
 70
 71        private AddressingVersion _addressingVersion;
 72        private AddressHeaderCollection _headers;
 73        private int _extensionSection;
 74        private int _metadataSection;
 75        private int _pspSection;
 76
 77        // these are the element name/namespace for the dummy wrapper element that wraps each buffer section
 78        internal const string DummyName = "Dummy";
 79        internal const string DummyNamespace = "http://Dummy";
 80
 081        private EndpointAddress(AddressingVersion version, Uri uri, EndpointIdentity identity, AddressHeaderCollection h
 82        {
 083            Init(version, uri, identity, headers, buffer, metadataSection, extensionSection, pspSection);
 084        }
 85
 386        public EndpointAddress(string uri)
 87        {
 388            if (uri == null)
 89            {
 090                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(uri));
 91            }
 92
 393            Uri u = new Uri(uri);
 94
 395            Init(u, (EndpointIdentity)null, (AddressHeaderCollection)null, null, -1, -1, -1);
 396        }
 97
 98        public EndpointAddress(Uri uri, params AddressHeader[] addressHeaders)
 418699            : this(uri, (EndpointIdentity)null, addressHeaders)
 100        {
 4186101        }
 102
 4186103        public EndpointAddress(Uri uri, EndpointIdentity identity, params AddressHeader[] addressHeaders)
 104        {
 4186105            if (uri == null)
 106            {
 0107                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(uri));
 108            }
 109
 4186110            Init(uri, identity, addressHeaders);
 4186111        }
 112
 0113        public EndpointAddress(Uri newUri, EndpointAddress oldEndpointAddress)
 114        {
 0115            Init(oldEndpointAddress._addressingVersion, newUri, oldEndpointAddress.Identity, oldEndpointAddress._headers
 0116        }
 117
 118        //public EndpointAddress(Uri uri, EndpointIdentity identity, AddressHeaderCollection headers)
 119        //{
 120        //    if (uri == null)
 121        //    {
 122        //        throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(uri));
 123        //    }
 124
 125        //    Init(uri, identity, headers, null, -1, -1, -1);
 126        //}
 127
 0128        internal EndpointAddress(Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlDictionaryReade
 129        {
 0130            if (uri == null)
 131            {
 0132                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(uri));
 133            }
 134
 0135            XmlBuffer buffer = null;
 0136            PossiblyPopulateBuffer(metadataReader, ref buffer, out _metadataSection);
 137
 0138            buffer = ReadExtensions(extensionReader, null, buffer, out EndpointIdentity ident2, out int extSection);
 139
 0140            if (identity != null && ident2 != null)
 141            {
 0142                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.MultipleIdentities, n
 143            }
 144
 0145            PossiblyPopulateBuffer(pspReader, ref buffer, out _pspSection);
 146
 0147            if (buffer != null)
 148            {
 0149                buffer.Close();
 150            }
 151
 0152            Init(uri, identity ?? ident2, headers, buffer, _metadataSection, extSection, _pspSection);
 0153        }
 154
 155        // metadataReader and extensionReader are assumed to not have a starting dummy wrapper element
 156        public EndpointAddress(Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlDictionaryReader 
 0157            : this(uri, identity, headers, metadataReader, extensionReader, null)
 158        {
 0159        }
 160
 161        private void Init(Uri uri, EndpointIdentity identity, AddressHeader[] headers)
 162        {
 4186163            if (headers == null || headers.Length == 0)
 164            {
 4186165                Init(uri, identity, (AddressHeaderCollection)null, null, -1, -1, -1);
 166            }
 167            else
 168            {
 0169                Init(uri, identity, new AddressHeaderCollection(headers), null, -1, -1, -1);
 170            }
 0171        }
 172
 173        private void Init(Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlBuffer buffer, int met
 174        {
 4189175            Init(null, uri, identity, headers, buffer, metadataSection, extensionSection, pspSection);
 4189176        }
 177
 178        private void Init(AddressingVersion version, Uri uri, EndpointIdentity identity, AddressHeaderCollection headers
 179        {
 4189180            if (!uri.IsAbsoluteUri)
 181            {
 0182                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(uri), SR.UriMustBeAbsolute);
 183            }
 184
 4189185            _addressingVersion = version;
 4189186            Uri = uri;
 4189187            Identity = identity;
 4189188            _headers = headers;
 4189189            Buffer = buffer;
 4189190            _metadataSection = metadataSection;
 4189191            _extensionSection = extensionSection;
 4189192            _pspSection = pspSection;
 193
 4189194            if (version != null)
 195            {
 0196                IsAnonymous = uri == version.AnonymousUri;
 0197                IsNone = uri == version.NoneUri;
 198            }
 199            else
 200            {
 4189201                IsAnonymous = ReferenceEquals(uri, AnonymousUri) || uri == AnonymousUri;
 4189202                IsNone = ReferenceEquals(uri, NoneUri) || uri == NoneUri;
 203            }
 4189204            if (IsAnonymous)
 205            {
 7206                Uri = AnonymousUri;
 207            }
 4189208            if (IsNone)
 209            {
 3210                Uri = NoneUri;
 211            }
 4189212        }
 213
 214        // TODO: This was internal, I needed to make it public. Is this a problem?
 215        public static EndpointAddress AnonymousAddress
 216        {
 217            get
 218            {
 678219                if (s_anonymousAddress == null)
 220                {
 4221                    s_anonymousAddress = new EndpointAddress(AnonymousUri);
 222                }
 223
 678224                return s_anonymousAddress;
 225            }
 226        }
 227
 228        public static Uri AnonymousUri
 229        {
 230            get
 231            {
 8387232                if (s_anonymousUri == null)
 233                {
 11234                    s_anonymousUri = new Uri(AddressingStrings.AnonymousUri);
 235                }
 236
 8387237                return s_anonymousUri;
 238            }
 239        }
 240
 241        public static Uri NoneUri
 242        {
 243            get
 244            {
 8383245                if (s_noneUri == null)
 246                {
 11247                    s_noneUri = new Uri(AddressingStrings.NoneUri);
 248                }
 249
 8383250                return s_noneUri;
 251            }
 252        }
 253
 4189254        internal XmlBuffer Buffer { get; private set; }
 255
 256        public AddressHeaderCollection Headers
 257        {
 258            get
 259            {
 1467260                if (_headers == null)
 261                {
 669262                    _headers = new AddressHeaderCollection();
 263                }
 264
 1467265                return _headers;
 266            }
 267        }
 268
 5528269        public EndpointIdentity Identity { get; private set; }
 270
 8579271        public bool IsAnonymous { get; private set; }
 272
 8703273        public bool IsNone { get; private set; }
 274
 13003275        public Uri Uri { get; private set; }
 276
 277        public void ApplyTo(Message message)
 278        {
 25279            if (message == null)
 280            {
 0281                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(message));
 282            }
 283
 25284            Uri uri = Uri;
 25285            if (IsAnonymous)
 286            {
 10287                if (message.Version.Addressing == AddressingVersion.WSAddressing10)
 288                {
 10289                    message.Headers.To = null;
 290                }
 291                else
 292                {
 0293                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
 0294                        new ProtocolException(SR.Format(SR.AddressingVersionNotSupported, message.Version.Addressing)));
 295                }
 296            }
 15297            else if (IsNone)
 298            {
 0299                message.Headers.To = message.Version.Addressing.NoneUri;
 300            }
 301            else
 302            {
 15303                message.Headers.To = uri;
 304            }
 25305            message.Properties.Via = message.Headers.To;
 25306            if (_headers != null)
 307            {
 10308                _headers.AddHeadersTo(message);
 309            }
 25310        }
 311
 312        // NOTE: UserInfo, Query, and Fragment are ignored when comparing Uris as addresses
 313        // this is the WCF logic for comparing Uris that represent addresses
 314        // this method must be kept in sync with UriGetHashCode
 315        internal static bool UriEquals(Uri u1, Uri u2, bool ignoreCase, bool includeHostInComparison)
 316        {
 5317            return UriEquals(u1, u2, ignoreCase, includeHostInComparison, true, true);
 318        }
 319
 320        internal static bool UriEquals(Uri u1, Uri u2, bool ignoreCase, bool includeHostInComparison, bool includePortIn
 321        {
 322            // PERF: Equals compares everything but UserInfo and Fragments.  It's more strict than
 323            //       we are, and faster, so it is done first.
 2479324            if (u1.Equals(u2))
 325            {
 1909326                return true;
 327            }
 328
 570329            if (includeSchemeInComparison)
 330            {
 6331                if (u1.Scheme != u2.Scheme)  // Uri.Scheme is always lowercase
 332                {
 0333                    return false;
 334                }
 335            }
 336
 570337            if (includePortInComparison)
 338            {
 6339                if (u1.Port != u2.Port)
 340                {
 0341                    return false;
 342                }
 343            }
 570344            if (includeHostInComparison)
 345            {
 0346                if (string.Compare(u1.Host, u2.Host, StringComparison.OrdinalIgnoreCase) != 0)
 347                {
 0348                    return false;
 349                }
 350            }
 351
 570352            if (string.Compare(u1.AbsolutePath, u2.AbsolutePath, ignoreCase ? StringComparison.OrdinalIgnoreCase : Strin
 353            {
 570354                return true;
 355            }
 356
 357            // Normalize for trailing slashes
 0358            string u1Path = u1.GetComponents(UriComponents.Path, UriFormat.Unescaped);
 0359            string u2Path = u2.GetComponents(UriComponents.Path, UriFormat.Unescaped);
 0360            int u1Len = (u1Path.Length > 0 && u1Path[u1Path.Length - 1] == '/') ? u1Path.Length - 1 : u1Path.Length;
 0361            int u2Len = (u2Path.Length > 0 && u2Path[u2Path.Length - 1] == '/') ? u2Path.Length - 1 : u2Path.Length;
 0362            if (u2Len != u1Len)
 363            {
 0364                return false;
 365            }
 0366            return string.Compare(u1Path, 0, u2Path, 0, u1Len, ignoreCase ? StringComparison.OrdinalIgnoreCase : StringC
 367        }
 368
 369        // this method must be kept in sync with UriEquals
 370        internal static int UriGetHashCode(Uri uri, bool includeHostInComparison)
 371        {
 3333372            return UriGetHashCode(uri, includeHostInComparison, true);
 373        }
 374
 375        internal static int UriGetHashCode(Uri uri, bool includeHostInComparison, bool includePortInComparison)
 376        {
 3333377            UriComponents components = UriComponents.Scheme | UriComponents.Path;
 378
 3333379            if (includePortInComparison)
 380            {
 3333381                components = components | UriComponents.Port;
 382            }
 3333383            if (includeHostInComparison)
 384            {
 3333385                components = components | UriComponents.Host;
 386            }
 387
 388            // Normalize for trailing slashes
 3333389            string uriString = uri.GetComponents(components, UriFormat.Unescaped);
 3333390            if (uriString.Length > 0 && uriString[uriString.Length - 1] != '/')
 391            {
 3283392                uriString = string.Concat(uriString, "/");
 393            }
 394
 3333395            return StringComparer.OrdinalIgnoreCase.GetHashCode(uriString);
 396        }
 397
 398        internal bool EndpointEquals(EndpointAddress endpointAddress)
 399        {
 3400            if (endpointAddress == null)
 401            {
 0402                return false;
 403            }
 404
 3405            if (ReferenceEquals(this, endpointAddress))
 406            {
 0407                return true;
 408            }
 409
 3410            Uri thisTo = Uri;
 3411            Uri otherTo = endpointAddress.Uri;
 412
 3413            if (!UriEquals(thisTo, otherTo, false /* ignoreCase */, true /* includeHostInComparison */))
 414            {
 0415                return false;
 416            }
 417
 3418            if (Identity == null)
 419            {
 3420                if (endpointAddress.Identity != null)
 421                {
 0422                    return false;
 423                }
 424            }
 0425            else if (!Identity.Equals(endpointAddress.Identity))
 426            {
 0427                return false;
 428            }
 429
 3430            if (!Headers.IsEquivalent(endpointAddress.Headers))
 431            {
 0432                return false;
 433            }
 434
 3435            return true;
 436        }
 437
 438        public override bool Equals(object obj)
 439        {
 1474440            if (ReferenceEquals(obj, this))
 441            {
 1471442                return true;
 443            }
 444
 3445            if (obj == null)
 446            {
 0447                return false;
 448            }
 449
 3450            EndpointAddress address = obj as EndpointAddress;
 3451            if (address == null)
 452            {
 0453                return false;
 454            }
 455
 3456            return EndpointEquals(address);
 457        }
 458
 459        public override int GetHashCode()
 460        {
 1987461            return UriGetHashCode(Uri, true /* includeHostInComparison */);
 462        }
 463
 464        // returns reader without starting dummy wrapper element
 465        internal XmlDictionaryReader GetReaderAtPsp()
 466        {
 0467            return GetReaderAtSection(Buffer, _pspSection);
 468        }
 469
 470        //// returns reader without starting dummy wrapper element
 471        internal XmlDictionaryReader GetReaderAtMetadata()
 472        {
 0473            return GetReaderAtSection(Buffer, _metadataSection);
 474        }
 475
 476        //// returns reader without starting dummy wrapper element
 477        internal XmlDictionaryReader GetReaderAtExtensions()
 478        {
 0479            return GetReaderAtSection(Buffer, _extensionSection);
 480        }
 481
 482        private static XmlDictionaryReader GetReaderAtSection(XmlBuffer buffer, int section)
 483        {
 0484            if (buffer == null || section < 0)
 485            {
 0486                return null;
 487            }
 488
 0489            XmlDictionaryReader reader = buffer.GetReader(section);
 0490            reader.MoveToContent();
 491            Fx.Assert(reader.Name == DummyName, "EndpointAddress: Expected dummy element not found");
 0492            reader.Read(); // consume the dummy wrapper element
 0493            return reader;
 494        }
 495
 496        private void PossiblyPopulateBuffer(XmlDictionaryReader reader, ref XmlBuffer buffer, out int section)
 497        {
 0498            if (reader == null)
 499            {
 0500                section = -1;
 501            }
 502            else
 503            {
 0504                if (buffer == null)
 505                {
 0506                    buffer = new XmlBuffer(short.MaxValue);
 507                }
 0508                section = buffer.SectionCount;
 0509                XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas);
 0510                writer.WriteStartElement(DummyName, DummyNamespace);
 0511                Copy(writer, reader);
 0512                buffer.CloseSection();
 513            }
 0514        }
 515
 516        public static EndpointAddress ReadFrom(XmlDictionaryReader reader)
 517        {
 518            AddressingVersion dummyVersion;
 0519            return ReadFrom(reader, out dummyVersion);
 520        }
 521
 522        internal static EndpointAddress ReadFrom(XmlDictionaryReader reader, out AddressingVersion version)
 523        {
 0524            if (reader == null)
 525            {
 0526                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader));
 527            }
 528
 0529            reader.ReadFullStartElement();
 0530            reader.MoveToContent();
 531
 0532            if (reader.IsNamespaceUri(AddressingVersion.WSAddressing10.DictionaryNamespace))
 533            {
 0534                version = AddressingVersion.WSAddressing10;
 535            }
 0536            else if (reader.IsNamespaceUri(AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
 537            {
 0538                version = AddressingVersion.WSAddressingAugust2004;
 539            }
 0540            else if (reader.NodeType != XmlNodeType.Element)
 541            {
 0542                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(
 0543                    nameof(reader), SR.CannotDetectAddressingVersion);
 544            }
 545            else
 546            {
 0547                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(
 0548                    nameof(reader), SR.Format(SR.AddressingVersionNotSupported, reader.NamespaceURI));
 549            }
 550
 0551            EndpointAddress ea = ReadFromDriver(version, reader);
 0552            reader.ReadEndElement();
 0553            return ea;
 554        }
 555
 556        //public static EndpointAddress ReadFrom(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionar
 557        //{
 558        //    AddressingVersion version;
 559        //    return ReadFrom(reader, localName, ns, out version);
 560        //}
 561
 562        internal static EndpointAddress ReadFrom(XmlDictionaryReader reader, XmlDictionaryString localName, XmlDictionar
 563        {
 0564            if (reader == null)
 565            {
 0566                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader));
 567            }
 568
 0569            reader.ReadFullStartElement(localName, ns);
 0570            reader.MoveToContent();
 571
 0572            if (reader.IsNamespaceUri(AddressingVersion.WSAddressing10.DictionaryNamespace))
 573            {
 0574                version = AddressingVersion.WSAddressing10;
 575            }
 0576            else if (reader.IsNamespaceUri(AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
 577            {
 0578                version = AddressingVersion.WSAddressingAugust2004;
 579            }
 0580            else if (reader.NodeType != XmlNodeType.Element)
 581            {
 0582                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(
 0583                    nameof(reader), SR.CannotDetectAddressingVersion);
 584            }
 585            else
 586            {
 0587                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(
 0588                    nameof(reader), SR.Format(SR.AddressingVersionNotSupported, reader.NamespaceURI));
 589            }
 590
 0591            EndpointAddress ea = ReadFromDriver(version, reader);
 0592            reader.ReadEndElement();
 0593            return ea;
 594        }
 595
 596        //public static EndpointAddress ReadFrom(AddressingVersion addressingVersion, XmlReader reader)
 597        //{
 598        //    return ReadFrom(addressingVersion, XmlDictionaryReader.CreateDictionaryReader(reader));
 599        //}
 600
 601        //public static EndpointAddress ReadFrom(AddressingVersion addressingVersion, XmlReader reader, string localName
 602        //{
 603        //    if (reader == null)
 604        //        throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader));
 605        //    if (addressingVersion == null)
 606        //        throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addressingVersion));
 607
 608        //    XmlDictionaryReader dictReader = XmlDictionaryReader.CreateDictionaryReader(reader);
 609        //    dictReader.ReadFullStartElement(localName, ns);
 610        //    EndpointAddress ea = ReadFromDriver(addressingVersion, dictReader);
 611        //    reader.ReadEndElement();
 612        //    return ea;
 613        //}
 614
 615        public static EndpointAddress ReadFrom(AddressingVersion addressingVersion, XmlDictionaryReader reader)
 616        {
 278617            if (reader == null)
 618            {
 0619                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader));
 620            }
 621
 278622            if (addressingVersion == null)
 623            {
 0624                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addressingVersion));
 625            }
 626
 278627            reader.ReadFullStartElement();
 278628            EndpointAddress ea = ReadFromDriver(addressingVersion, reader);
 278629            reader.ReadEndElement();
 278630            return ea;
 631        }
 632
 633        //public static EndpointAddress ReadFrom(AddressingVersion addressingVersion, XmlDictionaryReader reader, XmlDic
 634        //{
 635        //    if (reader == null)
 636        //        throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader));
 637        //    if (addressingVersion == null)
 638        //        throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addressingVersion));
 639
 640        //    reader.ReadFullStartElement(localName, ns);
 641        //    EndpointAddress ea = ReadFromDriver(addressingVersion, reader);
 642        //    reader.ReadEndElement();
 643        //    return ea;
 644        //}
 645
 646        private static EndpointAddress ReadFromDriver(AddressingVersion addressingVersion, XmlDictionaryReader reader)
 647        {
 648            AddressHeaderCollection headers;
 649            EndpointIdentity identity;
 650            Uri uri;
 651            XmlBuffer buffer;
 652            bool isAnonymous;
 653            int extensionSection;
 654            int metadataSection;
 278655            int pspSection = -1;
 656
 278657            if (addressingVersion == AddressingVersion.WSAddressing10)
 658            {
 263659                isAnonymous = ReadContentsFrom10(reader, out uri, out headers, out identity, out buffer, out metadataSec
 660            }
 15661            else if (addressingVersion == AddressingVersion.WSAddressingAugust2004)
 662            {
 15663                isAnonymous = ReadContentsFrom200408(reader, out uri, out headers, out identity, out buffer, out metadat
 664            }
 665            else
 666            {
 0667                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(addressingVersion),
 0668                    SR.Format(SR.AddressingVersionNotSupported, addressingVersion));
 669            }
 670
 278671            if (isAnonymous && headers == null && identity == null && buffer == null)
 672            {
 278673                return AnonymousAddress;
 674            }
 675            else
 676            {
 0677                return new EndpointAddress(addressingVersion, uri, identity, headers, buffer, metadataSection, extension
 678            }
 679        }
 680
 681        internal static XmlBuffer ReadExtensions(XmlDictionaryReader reader, AddressingVersion version, XmlBuffer buffer
 682        {
 278683            if (reader == null)
 684            {
 0685                identity = null;
 0686                section = -1;
 0687                return buffer;
 688            }
 689
 690            // EndpointIdentity and extensions
 278691            identity = null;
 278692            XmlDictionaryWriter bufferWriter = null;
 278693            reader.MoveToContent();
 278694            while (reader.IsStartElement())
 695            {
 0696                if (reader.IsStartElement(XD.AddressingDictionary.Identity, XD.AddressingDictionary.IdentityExtensionNam
 697                {
 0698                    if (identity != null)
 699                    {
 0700                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(S
 701                    }
 702
 0703                    identity = EndpointIdentity.ReadIdentity(reader);
 704                }
 0705                else if (version != null && reader.NamespaceURI == version.Namespace)
 706                {
 0707                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(SR.Ad
 708                }
 709                else
 710                {
 0711                    if (bufferWriter == null)
 712                    {
 0713                        if (buffer == null)
 714                        {
 0715                            buffer = new XmlBuffer(short.MaxValue);
 716                        }
 717
 0718                        bufferWriter = buffer.OpenSection(reader.Quotas);
 0719                        bufferWriter.WriteStartElement(DummyName, DummyNamespace);
 720                    }
 721
 0722                    bufferWriter.WriteNode(reader, true);
 723                }
 0724                reader.MoveToContent();
 725            }
 726
 278727            if (bufferWriter != null)
 728            {
 0729                bufferWriter.WriteEndElement();
 0730                buffer.CloseSection();
 0731                section = buffer.SectionCount - 1;
 732            }
 733            else
 734            {
 278735                section = -1;
 736            }
 737
 278738            return buffer;
 739        }
 740
 741        private static bool ReadContentsFrom200408(XmlDictionaryReader reader, out Uri uri, out AddressHeaderCollection 
 742        {
 15743            buffer = null;
 15744            headers = null;
 15745            extensionSection = -1;
 15746            metadataSection = -1;
 15747            pspSection = -1;
 748
 749            // Cache address string
 15750            reader.MoveToContent();
 15751            if (!reader.IsStartElement(XD.AddressingDictionary.Address, AddressingVersion.WSAddressingAugust2004.Diction
 752            {
 0753                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(SR.Unexpe
 754            }
 15755            string address = reader.ReadElementContentAsString();
 756
 757            // ReferenceProperites
 15758            reader.MoveToContent();
 15759            if (reader.IsStartElement(XD.AddressingDictionary.ReferenceProperties, AddressingVersion.WSAddressingAugust2
 760            {
 0761                headers = AddressHeaderCollection.ReadServiceParameters(reader, true);
 762            }
 763
 764            // ReferenceParameters
 15765            reader.MoveToContent();
 15766            if (reader.IsStartElement(XD.AddressingDictionary.ReferenceParameters, AddressingVersion.WSAddressingAugust2
 767            {
 0768                if (headers != null)
 769                {
 0770                    List<AddressHeader> headerList = new List<AddressHeader>();
 0771                    foreach (AddressHeader ah in headers)
 772                    {
 0773                        headerList.Add(ah);
 774                    }
 0775                    AddressHeaderCollection tmp = AddressHeaderCollection.ReadServiceParameters(reader);
 0776                    foreach (AddressHeader ah in tmp)
 777                    {
 0778                        headerList.Add(ah);
 779                    }
 0780                    headers = new AddressHeaderCollection(headerList);
 781                }
 782                else
 783                {
 0784                    headers = AddressHeaderCollection.ReadServiceParameters(reader);
 785                }
 786            }
 787
 15788            XmlDictionaryWriter bufferWriter = null;
 789
 790            // PortType
 15791            reader.MoveToContent();
 15792            if (reader.IsStartElement(XD.AddressingDictionary.PortType, AddressingVersion.WSAddressingAugust2004.Diction
 793            {
 0794                if (bufferWriter == null)
 795                {
 0796                    if (buffer == null)
 0797                        buffer = new XmlBuffer(short.MaxValue);
 0798                    bufferWriter = buffer.OpenSection(reader.Quotas);
 0799                    bufferWriter.WriteStartElement(DummyName, DummyNamespace);
 800                }
 0801                bufferWriter.WriteNode(reader, true);
 802            }
 803
 804            // ServiceName
 15805            reader.MoveToContent();
 15806            if (reader.IsStartElement(XD.AddressingDictionary.ServiceName, AddressingVersion.WSAddressingAugust2004.Dict
 807            {
 0808                if (bufferWriter == null)
 809                {
 0810                    if (buffer == null)
 0811                        buffer = new XmlBuffer(short.MaxValue);
 0812                    bufferWriter = buffer.OpenSection(reader.Quotas);
 0813                    bufferWriter.WriteStartElement(DummyName, DummyNamespace);
 814                }
 0815                bufferWriter.WriteNode(reader, true);
 816            }
 817
 818            // Policy
 15819            reader.MoveToContent();
 15820            while (reader.IsNamespaceUri(XD.PolicyDictionary.Namespace))
 821            {
 0822                if (bufferWriter == null)
 823                {
 0824                    if (buffer == null)
 0825                        buffer = new XmlBuffer(short.MaxValue);
 0826                    bufferWriter = buffer.OpenSection(reader.Quotas);
 0827                    bufferWriter.WriteStartElement(DummyName, DummyNamespace);
 828                }
 0829                bufferWriter.WriteNode(reader, true);
 0830                reader.MoveToContent();
 831            }
 832
 833            // Finish PSP
 15834            if (bufferWriter != null)
 835            {
 0836                bufferWriter.WriteEndElement();
 0837                buffer.CloseSection();
 0838                pspSection = buffer.SectionCount - 1;
 0839                bufferWriter = null;
 840            }
 841            else
 842            {
 15843                pspSection = -1;
 844            }
 845
 846
 847            // Metadata
 15848            if (reader.IsStartElement(Description.MetadataStrings.MetadataExchangeStrings.Metadata,
 15849                                      Description.MetadataStrings.MetadataExchangeStrings.Namespace))
 850            {
 0851                if (bufferWriter == null)
 852                {
 0853                    if (buffer == null)
 0854                        buffer = new XmlBuffer(short.MaxValue);
 0855                    bufferWriter = buffer.OpenSection(reader.Quotas);
 0856                    bufferWriter.WriteStartElement(DummyName, DummyNamespace);
 857                }
 0858                bufferWriter.WriteNode(reader, true);
 859            }
 860
 861            // Finish metadata
 15862            if (bufferWriter != null)
 863            {
 0864                bufferWriter.WriteEndElement();
 0865                buffer.CloseSection();
 0866                metadataSection = buffer.SectionCount - 1;
 867            }
 868            else
 869            {
 15870                metadataSection = -1;
 871            }
 872
 873            // Extensions
 15874            reader.MoveToContent();
 15875            buffer = ReadExtensions(reader, AddressingVersion.WSAddressingAugust2004, buffer, out identity, out extensio
 876
 877            // Finished reading
 15878            if (buffer != null)
 0879                buffer.Close();
 880
 881            // Process Address
 15882            if (address == Addressing200408Strings.Anonymous)
 883            {
 15884                uri = AddressingVersion.WSAddressingAugust2004.AnonymousUri;
 15885                if (headers == null && identity == null)
 15886                    return true;
 887            }
 888            else
 889            {
 0890                if (!Uri.TryCreate(address, UriKind.Absolute, out uri))
 0891                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.InvalidUriVa
 892            }
 893
 0894            return false;
 895        }
 896
 897        private static bool ReadContentsFrom10(XmlDictionaryReader reader, out Uri uri, out AddressHeaderCollection head
 898        {
 263899            buffer = null;
 263900            extensionSection = -1;
 263901            metadataSection = -1;
 902
 903            // Cache address string
 263904            if (!reader.IsStartElement(XD.AddressingDictionary.Address, XD.Addressing10Dictionary.Namespace))
 905            {
 0906                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(SR.Unexpe
 907            }
 908
 263909            string address = reader.ReadElementContentAsString();
 910
 911            // Headers
 263912            if (reader.IsStartElement(XD.AddressingDictionary.ReferenceParameters, XD.Addressing10Dictionary.Namespace))
 913            {
 0914                headers = AddressHeaderCollection.ReadServiceParameters(reader);
 915            }
 916            else
 917            {
 263918                headers = null;
 919            }
 920
 921            // Metadata
 263922            if (reader.IsStartElement(XD.Addressing10Dictionary.Metadata, XD.Addressing10Dictionary.Namespace))
 923            {
 0924                reader.ReadFullStartElement();  // the wsa10:Metadata element is never stored in the buffer
 0925                buffer = new XmlBuffer(short.MaxValue);
 0926                metadataSection = 0;
 0927                XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas);
 0928                writer.WriteStartElement(DummyName, DummyNamespace);
 0929                while (reader.NodeType != XmlNodeType.EndElement && !reader.EOF)
 930                {
 0931                    writer.WriteNode(reader, true);
 932                }
 0933                writer.Flush();
 0934                buffer.CloseSection();
 0935                reader.ReadEndElement();
 936            }
 937
 938            // Extensions
 263939            buffer = ReadExtensions(reader, AddressingVersion.WSAddressing10, buffer, out identity, out extensionSection
 263940            if (buffer != null)
 941            {
 0942                buffer.Close();
 943            }
 944
 945            // Process Address
 263946            if (address == Addressing10Strings.Anonymous)
 947            {
 263948                uri = AddressingVersion.WSAddressing10.AnonymousUri;
 263949                if (headers == null && identity == null)
 950                {
 263951                    return true;
 952                }
 953            }
 0954            else if (address == Addressing10Strings.NoneAddress)
 955            {
 0956                uri = AddressingVersion.WSAddressing10.NoneUri;
 0957                return false;
 958            }
 959            else
 960            {
 0961                if (!Uri.TryCreate(address, UriKind.Absolute, out uri))
 962                {
 0963                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.InvalidUriVa
 964                }
 965            }
 0966            return false;
 967        }
 968
 969        private static XmlException CreateXmlException(XmlDictionaryReader reader, string message)
 970        {
 0971            if (reader is IXmlLineInfo lineInfo)
 972            {
 0973                return new XmlException(message, null, lineInfo.LineNumber, lineInfo.LinePosition);
 974            }
 975
 0976            return new XmlException(message);
 977        }
 978
 979        // this function has a side-effect on the reader (MoveToContent)
 980        private static bool Done(XmlDictionaryReader reader)
 981        {
 0982            reader.MoveToContent();
 0983            return (reader.NodeType == XmlNodeType.EndElement || reader.EOF);
 984        }
 985
 986        // copy all of reader to writer
 987        internal static void Copy(XmlDictionaryWriter writer, XmlDictionaryReader reader)
 988        {
 0989            while (!Done(reader))
 990            {
 0991                writer.WriteNode(reader, true);
 992            }
 0993        }
 994
 995        public override string ToString()
 996        {
 0997            return Uri.ToString();
 998        }
 999
 1000        public void WriteContentsTo(AddressingVersion addressingVersion, XmlDictionaryWriter writer)
 1001        {
 211002            if (writer == null)
 1003            {
 01004                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(writer));
 1005            }
 1006
 211007            if (addressingVersion == null)
 1008            {
 01009                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addressingVersion));
 1010            }
 1011
 211012            if (addressingVersion == AddressingVersion.WSAddressing10)
 1013            {
 151014                WriteContentsTo10(writer);
 1015            }
 61016            else if (addressingVersion == AddressingVersion.WSAddressingAugust2004)
 1017            {
 31018                WriteContentsTo200408(writer);
 1019            }
 31020            else if (addressingVersion == AddressingVersion.None)
 1021            {
 31022                WriteContentsToNone(writer);
 1023            }
 1024            else
 1025            {
 01026                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(addressingVersion),
 01027                    SR.Format(SR.AddressingVersionNotSupported, addressingVersion));
 1028            }
 1029        }
 1030
 1031        private void WriteContentsToNone(XmlDictionaryWriter writer)
 1032        {
 31033            writer.WriteString(Uri.AbsoluteUri);
 31034        }
 1035
 1036        private void WriteContentsTo10(XmlDictionaryWriter writer)
 1037        {
 1038            // Address
 151039            writer.WriteStartElement(XD.AddressingDictionary.Address, XD.Addressing10Dictionary.Namespace);
 151040            if (IsAnonymous)
 1041            {
 11042                writer.WriteString(XD.Addressing10Dictionary.Anonymous);
 1043            }
 141044            else if (IsNone)
 1045            {
 11046                writer.WriteString(XD.Addressing10Dictionary.NoneAddress);
 1047            }
 1048            else
 1049            {
 131050                writer.WriteString(Uri.AbsoluteUri);
 1051            }
 151052            writer.WriteEndElement();
 1053
 1054            // Headers
 151055            if (_headers != null && _headers.Count > 0)
 1056            {
 01057                writer.WriteStartElement(XD.AddressingDictionary.ReferenceParameters, XD.Addressing10Dictionary.Namespac
 01058                _headers.WriteContentsTo(writer);
 01059                writer.WriteEndElement();
 1060            }
 1061
 1062            // Metadata
 151063            if (_metadataSection >= 0)
 1064            {
 01065                XmlDictionaryReader reader = GetReaderAtSection(Buffer, _metadataSection);
 01066                writer.WriteStartElement(XD.Addressing10Dictionary.Metadata, XD.Addressing10Dictionary.Namespace);
 01067                Copy(writer, reader);
 01068                writer.WriteEndElement();
 1069            }
 1070
 1071            // EndpointIdentity
 151072            if (Identity != null)
 1073            {
 01074                Identity.WriteTo(writer);
 1075            }
 1076
 1077            // Extensions
 151078            if (_extensionSection >= 0)
 1079            {
 01080                XmlDictionaryReader reader = GetReaderAtSection(Buffer, _extensionSection);
 01081                while (reader.IsStartElement())
 1082                {
 01083                    if (reader.NamespaceURI == AddressingVersion.WSAddressing10.Namespace)
 1084                    {
 01085                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(S
 1086                    }
 1087
 01088                    writer.WriteNode(reader, true);
 1089                }
 1090            }
 151091        }
 1092
 1093        private void WriteContentsTo200408(XmlDictionaryWriter writer)
 1094        {
 1095            // Address
 31096            writer.WriteStartElement(XD.AddressingDictionary.Address, XD.Addressing200408Dictionary.Namespace);
 31097            if (IsAnonymous)
 1098            {
 11099                writer.WriteString(XD.Addressing200408Dictionary.Anonymous);
 1100            }
 21101            else if (IsNone)
 1102            {
 11103                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("addressingVersion", SR.SFxNone2004);
 1104            }
 1105            else
 1106            {
 11107                writer.WriteString(Uri.AbsoluteUri);
 1108            }
 1109
 21110            writer.WriteEndElement();
 1111
 1112            // ReferenceProperties
 21113            if (Headers != null && Headers.Count > 0)
 1114            {
 01115                writer.WriteStartElement(XD.AddressingDictionary.ReferenceProperties, XD.Addressing200408Dictionary.Name
 01116                Headers.WriteContentsTo(writer);
 01117                writer.WriteEndElement();
 1118            }
 1119
 1120            // ReferenceParameters
 21121            if (Headers != null && Headers.Count > 0)
 1122            {
 01123                writer.WriteStartElement(XD.AddressingDictionary.ReferenceParameters, XD.Addressing200408Dictionary.Name
 01124                Headers.WriteContentsTo(writer);
 01125                writer.WriteEndElement();
 1126            }
 1127
 1128            // PSP (PortType, ServiceName, Policy)
 21129            XmlDictionaryReader reader = null;
 21130            if (_pspSection >= 0)
 1131            {
 01132                reader = GetReaderAtSection(Buffer, _pspSection);
 01133                Copy(writer, reader);
 1134            }
 1135
 1136            // Metadata
 21137            reader = null;
 21138            if (_metadataSection >= 0)
 1139            {
 01140                reader = GetReaderAtSection(Buffer, _metadataSection);
 01141                Copy(writer, reader);
 1142            }
 1143
 1144            // EndpointIdentity
 21145            if (Identity != null)
 1146            {
 01147                Identity.WriteTo(writer);
 1148            }
 1149
 1150            // Extensions
 21151            if (_extensionSection >= 0)
 1152            {
 01153                reader = GetReaderAtSection(Buffer, _extensionSection);
 01154                while (reader.IsStartElement())
 1155                {
 01156                    if (reader.NamespaceURI == AddressingVersion.WSAddressingAugust2004.Namespace)
 1157                    {
 01158                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(S
 1159                    }
 1160
 01161                    writer.WriteNode(reader, true);
 1162                }
 1163            }
 21164        }
 1165
 1166        public void WriteContentsTo(AddressingVersion addressingVersion, XmlWriter writer)
 1167        {
 91168            XmlDictionaryWriter dictionaryWriter = XmlDictionaryWriter.CreateDictionaryWriter(writer);
 91169            WriteContentsTo(addressingVersion, dictionaryWriter);
 81170        }
 1171
 1172        public void WriteTo(AddressingVersion addressingVersion, XmlDictionaryWriter writer, XmlDictionaryString localNa
 1173        {
 111174            if (writer == null)
 1175            {
 01176                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(writer));
 1177            }
 111178            if (addressingVersion == null)
 1179            {
 01180                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addressingVersion));
 1181            }
 111182            if (localName == null)
 1183            {
 01184                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(localName));
 1185            }
 111186            if (ns == null)
 1187            {
 01188                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(ns));
 1189            }
 111190            writer.WriteStartElement(localName, ns);
 111191            WriteContentsTo(addressingVersion, writer);
 111192            writer.WriteEndElement();
 111193        }
 1194
 1195        public void WriteTo(AddressingVersion addressingVersion, XmlWriter writer)
 1196        {
 111197            XmlDictionaryString dictionaryNamespace = addressingVersion.DictionaryNamespace;
 111198            if (dictionaryNamespace == null)
 1199            {
 01200                dictionaryNamespace = XD.AddressingDictionary.Empty;
 1201            }
 1202
 111203            WriteTo(addressingVersion, XmlDictionaryWriter.CreateDictionaryWriter(writer),
 111204                XD.AddressingDictionary.EndpointReference, dictionaryNamespace);
 111205        }
 1206
 1207        public static bool operator ==(EndpointAddress address1, EndpointAddress address2)
 1208        {
 33981209            if (ReferenceEquals(address2, null))
 1210            {
 32071211                return (ReferenceEquals(address1, null));
 1212            }
 1213
 1911214            return address2.Equals(address1);
 1215        }
 1216
 1217        public static bool operator !=(EndpointAddress address1, EndpointAddress address2)
 1218        {
 28091219            if (ReferenceEquals(address2, null))
 1220            {
 28091221                return !ReferenceEquals(address1, null);
 1222            }
 1223
 01224            return !address2.Equals(address1);
 1225        }
 1226    }
 1227
 1228    public class EndpointAddressBuilder
 1229    {
 1230        private XmlBuffer _extensionBuffer;  // this buffer is wrapped just like in EndpointAddress
 1231        private XmlBuffer _metadataBuffer;   // this buffer is wrapped just like in EndpointAddress
 1232        private bool _hasExtension;
 1233        private bool _hasMetadata;
 1234        private readonly EndpointAddress _epr;
 1235
 1236        public EndpointAddressBuilder()
 1237        {
 1238            Headers = new Collection<AddressHeader>();
 1239        }
 1240
 1241        public EndpointAddressBuilder(EndpointAddress address)
 1242        {
 1243            _epr = address ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(address));
 1244            Uri = address.Uri;
 1245            Identity = address.Identity;
 1246            Headers = new Collection<AddressHeader>();
 1247            for (int i = 0; i < address.Headers.Count; i++)
 1248            {
 1249                Headers.Add(address.Headers[i]);
 1250            }
 1251        }
 1252
 1253        public Uri Uri { get; set; }
 1254
 1255        public EndpointIdentity Identity { get; set; }
 1256
 1257        public Collection<AddressHeader> Headers { get; }
 1258
 1259        public XmlDictionaryReader GetReaderAtMetadata()
 1260        {
 1261            if (!_hasMetadata)
 1262            {
 1263                return _epr?.GetReaderAtMetadata();
 1264            }
 1265
 1266            if (_metadataBuffer == null)
 1267            {
 1268                return null;
 1269            }
 1270
 1271            XmlDictionaryReader reader = _metadataBuffer.GetReader(0);
 1272            reader.MoveToContent();
 1273            Fx.Assert(reader.Name == EndpointAddress.DummyName, "EndpointAddressBuilder: Expected dummy element not foun
 1274            reader.Read(); // consume the wrapper element
 1275            return reader;
 1276        }
 1277
 1278        public void SetMetadataReader(XmlDictionaryReader reader)
 1279        {
 1280            _hasMetadata = true;
 1281            _metadataBuffer = null;
 1282            if (reader != null)
 1283            {
 1284                _metadataBuffer = new XmlBuffer(short.MaxValue);
 1285                XmlDictionaryWriter writer = _metadataBuffer.OpenSection(reader.Quotas);
 1286                writer.WriteStartElement(EndpointAddress.DummyName, EndpointAddress.DummyNamespace);
 1287                EndpointAddress.Copy(writer, reader);
 1288                _metadataBuffer.CloseSection();
 1289                _metadataBuffer.Close();
 1290            }
 1291        }
 1292
 1293        public XmlDictionaryReader GetReaderAtExtensions()
 1294        {
 1295            if (!_hasExtension)
 1296            {
 1297                return _epr?.GetReaderAtExtensions();
 1298            }
 1299
 1300            if (_extensionBuffer == null)
 1301            {
 1302                return null;
 1303            }
 1304
 1305            XmlDictionaryReader reader = _extensionBuffer.GetReader(0);
 1306            reader.MoveToContent();
 1307            Fx.Assert(reader.Name == EndpointAddress.DummyName, "EndpointAddressBuilder: Expected dummy element not foun
 1308            reader.Read(); // consume the wrapper element
 1309            return reader;
 1310        }
 1311
 1312        public void SetExtensionReader(XmlDictionaryReader reader)
 1313        {
 1314            _hasExtension = true;
 1315            _extensionBuffer = EndpointAddress.ReadExtensions(reader, null, null, out EndpointIdentity identity, out int
 1316            if (_extensionBuffer != null)
 1317            {
 1318                _extensionBuffer.Close();
 1319            }
 1320            if (identity != null)
 1321            {
 1322                Identity = identity;
 1323            }
 1324        }
 1325
 1326        public EndpointAddress ToEndpointAddress()
 1327        {
 1328            return new EndpointAddress(
 1329                Uri,
 1330                Identity,
 1331                new AddressHeaderCollection(Headers),
 1332                GetReaderAtMetadata(),
 1333                GetReaderAtExtensions(),
 1334                _epr?.GetReaderAtPsp());
 1335        }
 1336    }
 1337}

Methods/Properties

.ctor(CoreWCF.Channels.AddressingVersion,System.Uri,CoreWCF.EndpointIdentity,CoreWCF.Channels.AddressHeaderCollection,CoreWCF.XmlBuffer,System.Int32,System.Int32,System.Int32)
.ctor(System.String)
.ctor(System.Uri,CoreWCF.Channels.AddressHeader[])
.ctor(System.Uri,CoreWCF.EndpointIdentity,CoreWCF.Channels.AddressHeader[])
.ctor(System.Uri,CoreWCF.EndpointAddress)
.ctor(System.Uri,CoreWCF.EndpointIdentity,CoreWCF.Channels.AddressHeaderCollection,System.Xml.XmlDictionaryReader,System.Xml.XmlDictionaryReader,System.Xml.XmlDictionaryReader)
.ctor(System.Uri,CoreWCF.EndpointIdentity,CoreWCF.Channels.AddressHeaderCollection,System.Xml.XmlDictionaryReader,System.Xml.XmlDictionaryReader)
Init(System.Uri,CoreWCF.EndpointIdentity,CoreWCF.Channels.AddressHeader[])
Init(System.Uri,CoreWCF.EndpointIdentity,CoreWCF.Channels.AddressHeaderCollection,CoreWCF.XmlBuffer,System.Int32,System.Int32,System.Int32)
Init(CoreWCF.Channels.AddressingVersion,System.Uri,CoreWCF.EndpointIdentity,CoreWCF.Channels.AddressHeaderCollection,CoreWCF.XmlBuffer,System.Int32,System.Int32,System.Int32)
AnonymousAddress()
AnonymousUri()
NoneUri()
Buffer()
Headers()
Identity()
IsAnonymous()
IsNone()
Uri()
ApplyTo(CoreWCF.Channels.Message)
UriEquals(System.Uri,System.Uri,System.Boolean,System.Boolean)
UriEquals(System.Uri,System.Uri,System.Boolean,System.Boolean,System.Boolean,System.Boolean)
UriGetHashCode(System.Uri,System.Boolean)
UriGetHashCode(System.Uri,System.Boolean,System.Boolean)
EndpointEquals(CoreWCF.EndpointAddress)
Equals(System.Object)
GetHashCode()
GetReaderAtPsp()
GetReaderAtMetadata()
GetReaderAtExtensions()
GetReaderAtSection(CoreWCF.XmlBuffer,System.Int32)
PossiblyPopulateBuffer(System.Xml.XmlDictionaryReader,CoreWCF.XmlBuffer&,System.Int32&)
ReadFrom(System.Xml.XmlDictionaryReader)
ReadFrom(System.Xml.XmlDictionaryReader,CoreWCF.Channels.AddressingVersion&)
ReadFrom(System.Xml.XmlDictionaryReader,System.Xml.XmlDictionaryString,System.Xml.XmlDictionaryString,CoreWCF.Channels.AddressingVersion&)
ReadFrom(CoreWCF.Channels.AddressingVersion,System.Xml.XmlDictionaryReader)
ReadFromDriver(CoreWCF.Channels.AddressingVersion,System.Xml.XmlDictionaryReader)
ReadExtensions(System.Xml.XmlDictionaryReader,CoreWCF.Channels.AddressingVersion,CoreWCF.XmlBuffer,CoreWCF.EndpointIdentity&,System.Int32&)
ReadContentsFrom200408(System.Xml.XmlDictionaryReader,System.Uri&,CoreWCF.Channels.AddressHeaderCollection&,CoreWCF.EndpointIdentity&,CoreWCF.XmlBuffer&,System.Int32&,System.Int32&,System.Int32&)
ReadContentsFrom10(System.Xml.XmlDictionaryReader,System.Uri&,CoreWCF.Channels.AddressHeaderCollection&,CoreWCF.EndpointIdentity&,CoreWCF.XmlBuffer&,System.Int32&,System.Int32&)
CreateXmlException(System.Xml.XmlDictionaryReader,System.String)
Done(System.Xml.XmlDictionaryReader)
Copy(System.Xml.XmlDictionaryWriter,System.Xml.XmlDictionaryReader)
ToString()
WriteContentsTo(CoreWCF.Channels.AddressingVersion,System.Xml.XmlDictionaryWriter)
WriteContentsToNone(System.Xml.XmlDictionaryWriter)
WriteContentsTo10(System.Xml.XmlDictionaryWriter)
WriteContentsTo200408(System.Xml.XmlDictionaryWriter)
WriteContentsTo(CoreWCF.Channels.AddressingVersion,System.Xml.XmlWriter)
WriteTo(CoreWCF.Channels.AddressingVersion,System.Xml.XmlDictionaryWriter,System.Xml.XmlDictionaryString,System.Xml.XmlDictionaryString)
WriteTo(CoreWCF.Channels.AddressingVersion,System.Xml.XmlWriter)
op_Equality(CoreWCF.EndpointAddress,CoreWCF.EndpointAddress)
op_Inequality(CoreWCF.EndpointAddress,CoreWCF.EndpointAddress)