< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.EndpointAddressBuilder
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/EndpointAddress.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 54
Coverable lines: 54
Total lines: 1337
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 24
Branch coverage: 0%
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(...)0%440%
GetReaderAtMetadata()0%660%
SetMetadataReader(...)0%220%
GetReaderAtExtensions()0%660%
SetExtensionReader(...)0%440%
ToEndpointAddress()0%220%

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
 81        private EndpointAddress(AddressingVersion version, Uri uri, EndpointIdentity identity, AddressHeaderCollection h
 82        {
 83            Init(version, uri, identity, headers, buffer, metadataSection, extensionSection, pspSection);
 84        }
 85
 86        public EndpointAddress(string uri)
 87        {
 88            if (uri == null)
 89            {
 90                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(uri));
 91            }
 92
 93            Uri u = new Uri(uri);
 94
 95            Init(u, (EndpointIdentity)null, (AddressHeaderCollection)null, null, -1, -1, -1);
 96        }
 97
 98        public EndpointAddress(Uri uri, params AddressHeader[] addressHeaders)
 99            : this(uri, (EndpointIdentity)null, addressHeaders)
 100        {
 101        }
 102
 103        public EndpointAddress(Uri uri, EndpointIdentity identity, params AddressHeader[] addressHeaders)
 104        {
 105            if (uri == null)
 106            {
 107                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(uri));
 108            }
 109
 110            Init(uri, identity, addressHeaders);
 111        }
 112
 113        public EndpointAddress(Uri newUri, EndpointAddress oldEndpointAddress)
 114        {
 115            Init(oldEndpointAddress._addressingVersion, newUri, oldEndpointAddress.Identity, oldEndpointAddress._headers
 116        }
 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
 128        internal EndpointAddress(Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlDictionaryReade
 129        {
 130            if (uri == null)
 131            {
 132                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(uri));
 133            }
 134
 135            XmlBuffer buffer = null;
 136            PossiblyPopulateBuffer(metadataReader, ref buffer, out _metadataSection);
 137
 138            buffer = ReadExtensions(extensionReader, null, buffer, out EndpointIdentity ident2, out int extSection);
 139
 140            if (identity != null && ident2 != null)
 141            {
 142                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.MultipleIdentities, n
 143            }
 144
 145            PossiblyPopulateBuffer(pspReader, ref buffer, out _pspSection);
 146
 147            if (buffer != null)
 148            {
 149                buffer.Close();
 150            }
 151
 152            Init(uri, identity ?? ident2, headers, buffer, _metadataSection, extSection, _pspSection);
 153        }
 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 
 157            : this(uri, identity, headers, metadataReader, extensionReader, null)
 158        {
 159        }
 160
 161        private void Init(Uri uri, EndpointIdentity identity, AddressHeader[] headers)
 162        {
 163            if (headers == null || headers.Length == 0)
 164            {
 165                Init(uri, identity, (AddressHeaderCollection)null, null, -1, -1, -1);
 166            }
 167            else
 168            {
 169                Init(uri, identity, new AddressHeaderCollection(headers), null, -1, -1, -1);
 170            }
 171        }
 172
 173        private void Init(Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlBuffer buffer, int met
 174        {
 175            Init(null, uri, identity, headers, buffer, metadataSection, extensionSection, pspSection);
 176        }
 177
 178        private void Init(AddressingVersion version, Uri uri, EndpointIdentity identity, AddressHeaderCollection headers
 179        {
 180            if (!uri.IsAbsoluteUri)
 181            {
 182                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(uri), SR.UriMustBeAbsolute);
 183            }
 184
 185            _addressingVersion = version;
 186            Uri = uri;
 187            Identity = identity;
 188            _headers = headers;
 189            Buffer = buffer;
 190            _metadataSection = metadataSection;
 191            _extensionSection = extensionSection;
 192            _pspSection = pspSection;
 193
 194            if (version != null)
 195            {
 196                IsAnonymous = uri == version.AnonymousUri;
 197                IsNone = uri == version.NoneUri;
 198            }
 199            else
 200            {
 201                IsAnonymous = ReferenceEquals(uri, AnonymousUri) || uri == AnonymousUri;
 202                IsNone = ReferenceEquals(uri, NoneUri) || uri == NoneUri;
 203            }
 204            if (IsAnonymous)
 205            {
 206                Uri = AnonymousUri;
 207            }
 208            if (IsNone)
 209            {
 210                Uri = NoneUri;
 211            }
 212        }
 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            {
 219                if (s_anonymousAddress == null)
 220                {
 221                    s_anonymousAddress = new EndpointAddress(AnonymousUri);
 222                }
 223
 224                return s_anonymousAddress;
 225            }
 226        }
 227
 228        public static Uri AnonymousUri
 229        {
 230            get
 231            {
 232                if (s_anonymousUri == null)
 233                {
 234                    s_anonymousUri = new Uri(AddressingStrings.AnonymousUri);
 235                }
 236
 237                return s_anonymousUri;
 238            }
 239        }
 240
 241        public static Uri NoneUri
 242        {
 243            get
 244            {
 245                if (s_noneUri == null)
 246                {
 247                    s_noneUri = new Uri(AddressingStrings.NoneUri);
 248                }
 249
 250                return s_noneUri;
 251            }
 252        }
 253
 254        internal XmlBuffer Buffer { get; private set; }
 255
 256        public AddressHeaderCollection Headers
 257        {
 258            get
 259            {
 260                if (_headers == null)
 261                {
 262                    _headers = new AddressHeaderCollection();
 263                }
 264
 265                return _headers;
 266            }
 267        }
 268
 269        public EndpointIdentity Identity { get; private set; }
 270
 271        public bool IsAnonymous { get; private set; }
 272
 273        public bool IsNone { get; private set; }
 274
 275        public Uri Uri { get; private set; }
 276
 277        public void ApplyTo(Message message)
 278        {
 279            if (message == null)
 280            {
 281                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(message));
 282            }
 283
 284            Uri uri = Uri;
 285            if (IsAnonymous)
 286            {
 287                if (message.Version.Addressing == AddressingVersion.WSAddressing10)
 288                {
 289                    message.Headers.To = null;
 290                }
 291                else
 292                {
 293                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
 294                        new ProtocolException(SR.Format(SR.AddressingVersionNotSupported, message.Version.Addressing)));
 295                }
 296            }
 297            else if (IsNone)
 298            {
 299                message.Headers.To = message.Version.Addressing.NoneUri;
 300            }
 301            else
 302            {
 303                message.Headers.To = uri;
 304            }
 305            message.Properties.Via = message.Headers.To;
 306            if (_headers != null)
 307            {
 308                _headers.AddHeadersTo(message);
 309            }
 310        }
 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        {
 317            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.
 324            if (u1.Equals(u2))
 325            {
 326                return true;
 327            }
 328
 329            if (includeSchemeInComparison)
 330            {
 331                if (u1.Scheme != u2.Scheme)  // Uri.Scheme is always lowercase
 332                {
 333                    return false;
 334                }
 335            }
 336
 337            if (includePortInComparison)
 338            {
 339                if (u1.Port != u2.Port)
 340                {
 341                    return false;
 342                }
 343            }
 344            if (includeHostInComparison)
 345            {
 346                if (string.Compare(u1.Host, u2.Host, StringComparison.OrdinalIgnoreCase) != 0)
 347                {
 348                    return false;
 349                }
 350            }
 351
 352            if (string.Compare(u1.AbsolutePath, u2.AbsolutePath, ignoreCase ? StringComparison.OrdinalIgnoreCase : Strin
 353            {
 354                return true;
 355            }
 356
 357            // Normalize for trailing slashes
 358            string u1Path = u1.GetComponents(UriComponents.Path, UriFormat.Unescaped);
 359            string u2Path = u2.GetComponents(UriComponents.Path, UriFormat.Unescaped);
 360            int u1Len = (u1Path.Length > 0 && u1Path[u1Path.Length - 1] == '/') ? u1Path.Length - 1 : u1Path.Length;
 361            int u2Len = (u2Path.Length > 0 && u2Path[u2Path.Length - 1] == '/') ? u2Path.Length - 1 : u2Path.Length;
 362            if (u2Len != u1Len)
 363            {
 364                return false;
 365            }
 366            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        {
 372            return UriGetHashCode(uri, includeHostInComparison, true);
 373        }
 374
 375        internal static int UriGetHashCode(Uri uri, bool includeHostInComparison, bool includePortInComparison)
 376        {
 377            UriComponents components = UriComponents.Scheme | UriComponents.Path;
 378
 379            if (includePortInComparison)
 380            {
 381                components = components | UriComponents.Port;
 382            }
 383            if (includeHostInComparison)
 384            {
 385                components = components | UriComponents.Host;
 386            }
 387
 388            // Normalize for trailing slashes
 389            string uriString = uri.GetComponents(components, UriFormat.Unescaped);
 390            if (uriString.Length > 0 && uriString[uriString.Length - 1] != '/')
 391            {
 392                uriString = string.Concat(uriString, "/");
 393            }
 394
 395            return StringComparer.OrdinalIgnoreCase.GetHashCode(uriString);
 396        }
 397
 398        internal bool EndpointEquals(EndpointAddress endpointAddress)
 399        {
 400            if (endpointAddress == null)
 401            {
 402                return false;
 403            }
 404
 405            if (ReferenceEquals(this, endpointAddress))
 406            {
 407                return true;
 408            }
 409
 410            Uri thisTo = Uri;
 411            Uri otherTo = endpointAddress.Uri;
 412
 413            if (!UriEquals(thisTo, otherTo, false /* ignoreCase */, true /* includeHostInComparison */))
 414            {
 415                return false;
 416            }
 417
 418            if (Identity == null)
 419            {
 420                if (endpointAddress.Identity != null)
 421                {
 422                    return false;
 423                }
 424            }
 425            else if (!Identity.Equals(endpointAddress.Identity))
 426            {
 427                return false;
 428            }
 429
 430            if (!Headers.IsEquivalent(endpointAddress.Headers))
 431            {
 432                return false;
 433            }
 434
 435            return true;
 436        }
 437
 438        public override bool Equals(object obj)
 439        {
 440            if (ReferenceEquals(obj, this))
 441            {
 442                return true;
 443            }
 444
 445            if (obj == null)
 446            {
 447                return false;
 448            }
 449
 450            EndpointAddress address = obj as EndpointAddress;
 451            if (address == null)
 452            {
 453                return false;
 454            }
 455
 456            return EndpointEquals(address);
 457        }
 458
 459        public override int GetHashCode()
 460        {
 461            return UriGetHashCode(Uri, true /* includeHostInComparison */);
 462        }
 463
 464        // returns reader without starting dummy wrapper element
 465        internal XmlDictionaryReader GetReaderAtPsp()
 466        {
 467            return GetReaderAtSection(Buffer, _pspSection);
 468        }
 469
 470        //// returns reader without starting dummy wrapper element
 471        internal XmlDictionaryReader GetReaderAtMetadata()
 472        {
 473            return GetReaderAtSection(Buffer, _metadataSection);
 474        }
 475
 476        //// returns reader without starting dummy wrapper element
 477        internal XmlDictionaryReader GetReaderAtExtensions()
 478        {
 479            return GetReaderAtSection(Buffer, _extensionSection);
 480        }
 481
 482        private static XmlDictionaryReader GetReaderAtSection(XmlBuffer buffer, int section)
 483        {
 484            if (buffer == null || section < 0)
 485            {
 486                return null;
 487            }
 488
 489            XmlDictionaryReader reader = buffer.GetReader(section);
 490            reader.MoveToContent();
 491            Fx.Assert(reader.Name == DummyName, "EndpointAddress: Expected dummy element not found");
 492            reader.Read(); // consume the dummy wrapper element
 493            return reader;
 494        }
 495
 496        private void PossiblyPopulateBuffer(XmlDictionaryReader reader, ref XmlBuffer buffer, out int section)
 497        {
 498            if (reader == null)
 499            {
 500                section = -1;
 501            }
 502            else
 503            {
 504                if (buffer == null)
 505                {
 506                    buffer = new XmlBuffer(short.MaxValue);
 507                }
 508                section = buffer.SectionCount;
 509                XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas);
 510                writer.WriteStartElement(DummyName, DummyNamespace);
 511                Copy(writer, reader);
 512                buffer.CloseSection();
 513            }
 514        }
 515
 516        public static EndpointAddress ReadFrom(XmlDictionaryReader reader)
 517        {
 518            AddressingVersion dummyVersion;
 519            return ReadFrom(reader, out dummyVersion);
 520        }
 521
 522        internal static EndpointAddress ReadFrom(XmlDictionaryReader reader, out AddressingVersion version)
 523        {
 524            if (reader == null)
 525            {
 526                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader));
 527            }
 528
 529            reader.ReadFullStartElement();
 530            reader.MoveToContent();
 531
 532            if (reader.IsNamespaceUri(AddressingVersion.WSAddressing10.DictionaryNamespace))
 533            {
 534                version = AddressingVersion.WSAddressing10;
 535            }
 536            else if (reader.IsNamespaceUri(AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
 537            {
 538                version = AddressingVersion.WSAddressingAugust2004;
 539            }
 540            else if (reader.NodeType != XmlNodeType.Element)
 541            {
 542                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(
 543                    nameof(reader), SR.CannotDetectAddressingVersion);
 544            }
 545            else
 546            {
 547                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(
 548                    nameof(reader), SR.Format(SR.AddressingVersionNotSupported, reader.NamespaceURI));
 549            }
 550
 551            EndpointAddress ea = ReadFromDriver(version, reader);
 552            reader.ReadEndElement();
 553            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        {
 564            if (reader == null)
 565            {
 566                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader));
 567            }
 568
 569            reader.ReadFullStartElement(localName, ns);
 570            reader.MoveToContent();
 571
 572            if (reader.IsNamespaceUri(AddressingVersion.WSAddressing10.DictionaryNamespace))
 573            {
 574                version = AddressingVersion.WSAddressing10;
 575            }
 576            else if (reader.IsNamespaceUri(AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
 577            {
 578                version = AddressingVersion.WSAddressingAugust2004;
 579            }
 580            else if (reader.NodeType != XmlNodeType.Element)
 581            {
 582                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(
 583                    nameof(reader), SR.CannotDetectAddressingVersion);
 584            }
 585            else
 586            {
 587                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(
 588                    nameof(reader), SR.Format(SR.AddressingVersionNotSupported, reader.NamespaceURI));
 589            }
 590
 591            EndpointAddress ea = ReadFromDriver(version, reader);
 592            reader.ReadEndElement();
 593            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        {
 617            if (reader == null)
 618            {
 619                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reader));
 620            }
 621
 622            if (addressingVersion == null)
 623            {
 624                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addressingVersion));
 625            }
 626
 627            reader.ReadFullStartElement();
 628            EndpointAddress ea = ReadFromDriver(addressingVersion, reader);
 629            reader.ReadEndElement();
 630            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;
 655            int pspSection = -1;
 656
 657            if (addressingVersion == AddressingVersion.WSAddressing10)
 658            {
 659                isAnonymous = ReadContentsFrom10(reader, out uri, out headers, out identity, out buffer, out metadataSec
 660            }
 661            else if (addressingVersion == AddressingVersion.WSAddressingAugust2004)
 662            {
 663                isAnonymous = ReadContentsFrom200408(reader, out uri, out headers, out identity, out buffer, out metadat
 664            }
 665            else
 666            {
 667                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(addressingVersion),
 668                    SR.Format(SR.AddressingVersionNotSupported, addressingVersion));
 669            }
 670
 671            if (isAnonymous && headers == null && identity == null && buffer == null)
 672            {
 673                return AnonymousAddress;
 674            }
 675            else
 676            {
 677                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        {
 683            if (reader == null)
 684            {
 685                identity = null;
 686                section = -1;
 687                return buffer;
 688            }
 689
 690            // EndpointIdentity and extensions
 691            identity = null;
 692            XmlDictionaryWriter bufferWriter = null;
 693            reader.MoveToContent();
 694            while (reader.IsStartElement())
 695            {
 696                if (reader.IsStartElement(XD.AddressingDictionary.Identity, XD.AddressingDictionary.IdentityExtensionNam
 697                {
 698                    if (identity != null)
 699                    {
 700                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(S
 701                    }
 702
 703                    identity = EndpointIdentity.ReadIdentity(reader);
 704                }
 705                else if (version != null && reader.NamespaceURI == version.Namespace)
 706                {
 707                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(SR.Ad
 708                }
 709                else
 710                {
 711                    if (bufferWriter == null)
 712                    {
 713                        if (buffer == null)
 714                        {
 715                            buffer = new XmlBuffer(short.MaxValue);
 716                        }
 717
 718                        bufferWriter = buffer.OpenSection(reader.Quotas);
 719                        bufferWriter.WriteStartElement(DummyName, DummyNamespace);
 720                    }
 721
 722                    bufferWriter.WriteNode(reader, true);
 723                }
 724                reader.MoveToContent();
 725            }
 726
 727            if (bufferWriter != null)
 728            {
 729                bufferWriter.WriteEndElement();
 730                buffer.CloseSection();
 731                section = buffer.SectionCount - 1;
 732            }
 733            else
 734            {
 735                section = -1;
 736            }
 737
 738            return buffer;
 739        }
 740
 741        private static bool ReadContentsFrom200408(XmlDictionaryReader reader, out Uri uri, out AddressHeaderCollection 
 742        {
 743            buffer = null;
 744            headers = null;
 745            extensionSection = -1;
 746            metadataSection = -1;
 747            pspSection = -1;
 748
 749            // Cache address string
 750            reader.MoveToContent();
 751            if (!reader.IsStartElement(XD.AddressingDictionary.Address, AddressingVersion.WSAddressingAugust2004.Diction
 752            {
 753                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(SR.Unexpe
 754            }
 755            string address = reader.ReadElementContentAsString();
 756
 757            // ReferenceProperites
 758            reader.MoveToContent();
 759            if (reader.IsStartElement(XD.AddressingDictionary.ReferenceProperties, AddressingVersion.WSAddressingAugust2
 760            {
 761                headers = AddressHeaderCollection.ReadServiceParameters(reader, true);
 762            }
 763
 764            // ReferenceParameters
 765            reader.MoveToContent();
 766            if (reader.IsStartElement(XD.AddressingDictionary.ReferenceParameters, AddressingVersion.WSAddressingAugust2
 767            {
 768                if (headers != null)
 769                {
 770                    List<AddressHeader> headerList = new List<AddressHeader>();
 771                    foreach (AddressHeader ah in headers)
 772                    {
 773                        headerList.Add(ah);
 774                    }
 775                    AddressHeaderCollection tmp = AddressHeaderCollection.ReadServiceParameters(reader);
 776                    foreach (AddressHeader ah in tmp)
 777                    {
 778                        headerList.Add(ah);
 779                    }
 780                    headers = new AddressHeaderCollection(headerList);
 781                }
 782                else
 783                {
 784                    headers = AddressHeaderCollection.ReadServiceParameters(reader);
 785                }
 786            }
 787
 788            XmlDictionaryWriter bufferWriter = null;
 789
 790            // PortType
 791            reader.MoveToContent();
 792            if (reader.IsStartElement(XD.AddressingDictionary.PortType, AddressingVersion.WSAddressingAugust2004.Diction
 793            {
 794                if (bufferWriter == null)
 795                {
 796                    if (buffer == null)
 797                        buffer = new XmlBuffer(short.MaxValue);
 798                    bufferWriter = buffer.OpenSection(reader.Quotas);
 799                    bufferWriter.WriteStartElement(DummyName, DummyNamespace);
 800                }
 801                bufferWriter.WriteNode(reader, true);
 802            }
 803
 804            // ServiceName
 805            reader.MoveToContent();
 806            if (reader.IsStartElement(XD.AddressingDictionary.ServiceName, AddressingVersion.WSAddressingAugust2004.Dict
 807            {
 808                if (bufferWriter == null)
 809                {
 810                    if (buffer == null)
 811                        buffer = new XmlBuffer(short.MaxValue);
 812                    bufferWriter = buffer.OpenSection(reader.Quotas);
 813                    bufferWriter.WriteStartElement(DummyName, DummyNamespace);
 814                }
 815                bufferWriter.WriteNode(reader, true);
 816            }
 817
 818            // Policy
 819            reader.MoveToContent();
 820            while (reader.IsNamespaceUri(XD.PolicyDictionary.Namespace))
 821            {
 822                if (bufferWriter == null)
 823                {
 824                    if (buffer == null)
 825                        buffer = new XmlBuffer(short.MaxValue);
 826                    bufferWriter = buffer.OpenSection(reader.Quotas);
 827                    bufferWriter.WriteStartElement(DummyName, DummyNamespace);
 828                }
 829                bufferWriter.WriteNode(reader, true);
 830                reader.MoveToContent();
 831            }
 832
 833            // Finish PSP
 834            if (bufferWriter != null)
 835            {
 836                bufferWriter.WriteEndElement();
 837                buffer.CloseSection();
 838                pspSection = buffer.SectionCount - 1;
 839                bufferWriter = null;
 840            }
 841            else
 842            {
 843                pspSection = -1;
 844            }
 845
 846
 847            // Metadata
 848            if (reader.IsStartElement(Description.MetadataStrings.MetadataExchangeStrings.Metadata,
 849                                      Description.MetadataStrings.MetadataExchangeStrings.Namespace))
 850            {
 851                if (bufferWriter == null)
 852                {
 853                    if (buffer == null)
 854                        buffer = new XmlBuffer(short.MaxValue);
 855                    bufferWriter = buffer.OpenSection(reader.Quotas);
 856                    bufferWriter.WriteStartElement(DummyName, DummyNamespace);
 857                }
 858                bufferWriter.WriteNode(reader, true);
 859            }
 860
 861            // Finish metadata
 862            if (bufferWriter != null)
 863            {
 864                bufferWriter.WriteEndElement();
 865                buffer.CloseSection();
 866                metadataSection = buffer.SectionCount - 1;
 867            }
 868            else
 869            {
 870                metadataSection = -1;
 871            }
 872
 873            // Extensions
 874            reader.MoveToContent();
 875            buffer = ReadExtensions(reader, AddressingVersion.WSAddressingAugust2004, buffer, out identity, out extensio
 876
 877            // Finished reading
 878            if (buffer != null)
 879                buffer.Close();
 880
 881            // Process Address
 882            if (address == Addressing200408Strings.Anonymous)
 883            {
 884                uri = AddressingVersion.WSAddressingAugust2004.AnonymousUri;
 885                if (headers == null && identity == null)
 886                    return true;
 887            }
 888            else
 889            {
 890                if (!Uri.TryCreate(address, UriKind.Absolute, out uri))
 891                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.InvalidUriVa
 892            }
 893
 894            return false;
 895        }
 896
 897        private static bool ReadContentsFrom10(XmlDictionaryReader reader, out Uri uri, out AddressHeaderCollection head
 898        {
 899            buffer = null;
 900            extensionSection = -1;
 901            metadataSection = -1;
 902
 903            // Cache address string
 904            if (!reader.IsStartElement(XD.AddressingDictionary.Address, XD.Addressing10Dictionary.Namespace))
 905            {
 906                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(SR.Unexpe
 907            }
 908
 909            string address = reader.ReadElementContentAsString();
 910
 911            // Headers
 912            if (reader.IsStartElement(XD.AddressingDictionary.ReferenceParameters, XD.Addressing10Dictionary.Namespace))
 913            {
 914                headers = AddressHeaderCollection.ReadServiceParameters(reader);
 915            }
 916            else
 917            {
 918                headers = null;
 919            }
 920
 921            // Metadata
 922            if (reader.IsStartElement(XD.Addressing10Dictionary.Metadata, XD.Addressing10Dictionary.Namespace))
 923            {
 924                reader.ReadFullStartElement();  // the wsa10:Metadata element is never stored in the buffer
 925                buffer = new XmlBuffer(short.MaxValue);
 926                metadataSection = 0;
 927                XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas);
 928                writer.WriteStartElement(DummyName, DummyNamespace);
 929                while (reader.NodeType != XmlNodeType.EndElement && !reader.EOF)
 930                {
 931                    writer.WriteNode(reader, true);
 932                }
 933                writer.Flush();
 934                buffer.CloseSection();
 935                reader.ReadEndElement();
 936            }
 937
 938            // Extensions
 939            buffer = ReadExtensions(reader, AddressingVersion.WSAddressing10, buffer, out identity, out extensionSection
 940            if (buffer != null)
 941            {
 942                buffer.Close();
 943            }
 944
 945            // Process Address
 946            if (address == Addressing10Strings.Anonymous)
 947            {
 948                uri = AddressingVersion.WSAddressing10.AnonymousUri;
 949                if (headers == null && identity == null)
 950                {
 951                    return true;
 952                }
 953            }
 954            else if (address == Addressing10Strings.NoneAddress)
 955            {
 956                uri = AddressingVersion.WSAddressing10.NoneUri;
 957                return false;
 958            }
 959            else
 960            {
 961                if (!Uri.TryCreate(address, UriKind.Absolute, out uri))
 962                {
 963                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.InvalidUriVa
 964                }
 965            }
 966            return false;
 967        }
 968
 969        private static XmlException CreateXmlException(XmlDictionaryReader reader, string message)
 970        {
 971            if (reader is IXmlLineInfo lineInfo)
 972            {
 973                return new XmlException(message, null, lineInfo.LineNumber, lineInfo.LinePosition);
 974            }
 975
 976            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        {
 982            reader.MoveToContent();
 983            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        {
 989            while (!Done(reader))
 990            {
 991                writer.WriteNode(reader, true);
 992            }
 993        }
 994
 995        public override string ToString()
 996        {
 997            return Uri.ToString();
 998        }
 999
 1000        public void WriteContentsTo(AddressingVersion addressingVersion, XmlDictionaryWriter writer)
 1001        {
 1002            if (writer == null)
 1003            {
 1004                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(writer));
 1005            }
 1006
 1007            if (addressingVersion == null)
 1008            {
 1009                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addressingVersion));
 1010            }
 1011
 1012            if (addressingVersion == AddressingVersion.WSAddressing10)
 1013            {
 1014                WriteContentsTo10(writer);
 1015            }
 1016            else if (addressingVersion == AddressingVersion.WSAddressingAugust2004)
 1017            {
 1018                WriteContentsTo200408(writer);
 1019            }
 1020            else if (addressingVersion == AddressingVersion.None)
 1021            {
 1022                WriteContentsToNone(writer);
 1023            }
 1024            else
 1025            {
 1026                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(addressingVersion),
 1027                    SR.Format(SR.AddressingVersionNotSupported, addressingVersion));
 1028            }
 1029        }
 1030
 1031        private void WriteContentsToNone(XmlDictionaryWriter writer)
 1032        {
 1033            writer.WriteString(Uri.AbsoluteUri);
 1034        }
 1035
 1036        private void WriteContentsTo10(XmlDictionaryWriter writer)
 1037        {
 1038            // Address
 1039            writer.WriteStartElement(XD.AddressingDictionary.Address, XD.Addressing10Dictionary.Namespace);
 1040            if (IsAnonymous)
 1041            {
 1042                writer.WriteString(XD.Addressing10Dictionary.Anonymous);
 1043            }
 1044            else if (IsNone)
 1045            {
 1046                writer.WriteString(XD.Addressing10Dictionary.NoneAddress);
 1047            }
 1048            else
 1049            {
 1050                writer.WriteString(Uri.AbsoluteUri);
 1051            }
 1052            writer.WriteEndElement();
 1053
 1054            // Headers
 1055            if (_headers != null && _headers.Count > 0)
 1056            {
 1057                writer.WriteStartElement(XD.AddressingDictionary.ReferenceParameters, XD.Addressing10Dictionary.Namespac
 1058                _headers.WriteContentsTo(writer);
 1059                writer.WriteEndElement();
 1060            }
 1061
 1062            // Metadata
 1063            if (_metadataSection >= 0)
 1064            {
 1065                XmlDictionaryReader reader = GetReaderAtSection(Buffer, _metadataSection);
 1066                writer.WriteStartElement(XD.Addressing10Dictionary.Metadata, XD.Addressing10Dictionary.Namespace);
 1067                Copy(writer, reader);
 1068                writer.WriteEndElement();
 1069            }
 1070
 1071            // EndpointIdentity
 1072            if (Identity != null)
 1073            {
 1074                Identity.WriteTo(writer);
 1075            }
 1076
 1077            // Extensions
 1078            if (_extensionSection >= 0)
 1079            {
 1080                XmlDictionaryReader reader = GetReaderAtSection(Buffer, _extensionSection);
 1081                while (reader.IsStartElement())
 1082                {
 1083                    if (reader.NamespaceURI == AddressingVersion.WSAddressing10.Namespace)
 1084                    {
 1085                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(S
 1086                    }
 1087
 1088                    writer.WriteNode(reader, true);
 1089                }
 1090            }
 1091        }
 1092
 1093        private void WriteContentsTo200408(XmlDictionaryWriter writer)
 1094        {
 1095            // Address
 1096            writer.WriteStartElement(XD.AddressingDictionary.Address, XD.Addressing200408Dictionary.Namespace);
 1097            if (IsAnonymous)
 1098            {
 1099                writer.WriteString(XD.Addressing200408Dictionary.Anonymous);
 1100            }
 1101            else if (IsNone)
 1102            {
 1103                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("addressingVersion", SR.SFxNone2004);
 1104            }
 1105            else
 1106            {
 1107                writer.WriteString(Uri.AbsoluteUri);
 1108            }
 1109
 1110            writer.WriteEndElement();
 1111
 1112            // ReferenceProperties
 1113            if (Headers != null && Headers.Count > 0)
 1114            {
 1115                writer.WriteStartElement(XD.AddressingDictionary.ReferenceProperties, XD.Addressing200408Dictionary.Name
 1116                Headers.WriteContentsTo(writer);
 1117                writer.WriteEndElement();
 1118            }
 1119
 1120            // ReferenceParameters
 1121            if (Headers != null && Headers.Count > 0)
 1122            {
 1123                writer.WriteStartElement(XD.AddressingDictionary.ReferenceParameters, XD.Addressing200408Dictionary.Name
 1124                Headers.WriteContentsTo(writer);
 1125                writer.WriteEndElement();
 1126            }
 1127
 1128            // PSP (PortType, ServiceName, Policy)
 1129            XmlDictionaryReader reader = null;
 1130            if (_pspSection >= 0)
 1131            {
 1132                reader = GetReaderAtSection(Buffer, _pspSection);
 1133                Copy(writer, reader);
 1134            }
 1135
 1136            // Metadata
 1137            reader = null;
 1138            if (_metadataSection >= 0)
 1139            {
 1140                reader = GetReaderAtSection(Buffer, _metadataSection);
 1141                Copy(writer, reader);
 1142            }
 1143
 1144            // EndpointIdentity
 1145            if (Identity != null)
 1146            {
 1147                Identity.WriteTo(writer);
 1148            }
 1149
 1150            // Extensions
 1151            if (_extensionSection >= 0)
 1152            {
 1153                reader = GetReaderAtSection(Buffer, _extensionSection);
 1154                while (reader.IsStartElement())
 1155                {
 1156                    if (reader.NamespaceURI == AddressingVersion.WSAddressingAugust2004.Namespace)
 1157                    {
 1158                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(S
 1159                    }
 1160
 1161                    writer.WriteNode(reader, true);
 1162                }
 1163            }
 1164        }
 1165
 1166        public void WriteContentsTo(AddressingVersion addressingVersion, XmlWriter writer)
 1167        {
 1168            XmlDictionaryWriter dictionaryWriter = XmlDictionaryWriter.CreateDictionaryWriter(writer);
 1169            WriteContentsTo(addressingVersion, dictionaryWriter);
 1170        }
 1171
 1172        public void WriteTo(AddressingVersion addressingVersion, XmlDictionaryWriter writer, XmlDictionaryString localNa
 1173        {
 1174            if (writer == null)
 1175            {
 1176                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(writer));
 1177            }
 1178            if (addressingVersion == null)
 1179            {
 1180                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addressingVersion));
 1181            }
 1182            if (localName == null)
 1183            {
 1184                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(localName));
 1185            }
 1186            if (ns == null)
 1187            {
 1188                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(ns));
 1189            }
 1190            writer.WriteStartElement(localName, ns);
 1191            WriteContentsTo(addressingVersion, writer);
 1192            writer.WriteEndElement();
 1193        }
 1194
 1195        public void WriteTo(AddressingVersion addressingVersion, XmlWriter writer)
 1196        {
 1197            XmlDictionaryString dictionaryNamespace = addressingVersion.DictionaryNamespace;
 1198            if (dictionaryNamespace == null)
 1199            {
 1200                dictionaryNamespace = XD.AddressingDictionary.Empty;
 1201            }
 1202
 1203            WriteTo(addressingVersion, XmlDictionaryWriter.CreateDictionaryWriter(writer),
 1204                XD.AddressingDictionary.EndpointReference, dictionaryNamespace);
 1205        }
 1206
 1207        public static bool operator ==(EndpointAddress address1, EndpointAddress address2)
 1208        {
 1209            if (ReferenceEquals(address2, null))
 1210            {
 1211                return (ReferenceEquals(address1, null));
 1212            }
 1213
 1214            return address2.Equals(address1);
 1215        }
 1216
 1217        public static bool operator !=(EndpointAddress address1, EndpointAddress address2)
 1218        {
 1219            if (ReferenceEquals(address2, null))
 1220            {
 1221                return !ReferenceEquals(address1, null);
 1222            }
 1223
 1224            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
 01236        public EndpointAddressBuilder()
 1237        {
 01238            Headers = new Collection<AddressHeader>();
 01239        }
 1240
 01241        public EndpointAddressBuilder(EndpointAddress address)
 1242        {
 01243            _epr = address ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(address));
 01244            Uri = address.Uri;
 01245            Identity = address.Identity;
 01246            Headers = new Collection<AddressHeader>();
 01247            for (int i = 0; i < address.Headers.Count; i++)
 1248            {
 01249                Headers.Add(address.Headers[i]);
 1250            }
 01251        }
 1252
 01253        public Uri Uri { get; set; }
 1254
 01255        public EndpointIdentity Identity { get; set; }
 1256
 01257        public Collection<AddressHeader> Headers { get; }
 1258
 1259        public XmlDictionaryReader GetReaderAtMetadata()
 1260        {
 01261            if (!_hasMetadata)
 1262            {
 01263                return _epr?.GetReaderAtMetadata();
 1264            }
 1265
 01266            if (_metadataBuffer == null)
 1267            {
 01268                return null;
 1269            }
 1270
 01271            XmlDictionaryReader reader = _metadataBuffer.GetReader(0);
 01272            reader.MoveToContent();
 1273            Fx.Assert(reader.Name == EndpointAddress.DummyName, "EndpointAddressBuilder: Expected dummy element not foun
 01274            reader.Read(); // consume the wrapper element
 01275            return reader;
 1276        }
 1277
 1278        public void SetMetadataReader(XmlDictionaryReader reader)
 1279        {
 01280            _hasMetadata = true;
 01281            _metadataBuffer = null;
 01282            if (reader != null)
 1283            {
 01284                _metadataBuffer = new XmlBuffer(short.MaxValue);
 01285                XmlDictionaryWriter writer = _metadataBuffer.OpenSection(reader.Quotas);
 01286                writer.WriteStartElement(EndpointAddress.DummyName, EndpointAddress.DummyNamespace);
 01287                EndpointAddress.Copy(writer, reader);
 01288                _metadataBuffer.CloseSection();
 01289                _metadataBuffer.Close();
 1290            }
 01291        }
 1292
 1293        public XmlDictionaryReader GetReaderAtExtensions()
 1294        {
 01295            if (!_hasExtension)
 1296            {
 01297                return _epr?.GetReaderAtExtensions();
 1298            }
 1299
 01300            if (_extensionBuffer == null)
 1301            {
 01302                return null;
 1303            }
 1304
 01305            XmlDictionaryReader reader = _extensionBuffer.GetReader(0);
 01306            reader.MoveToContent();
 1307            Fx.Assert(reader.Name == EndpointAddress.DummyName, "EndpointAddressBuilder: Expected dummy element not foun
 01308            reader.Read(); // consume the wrapper element
 01309            return reader;
 1310        }
 1311
 1312        public void SetExtensionReader(XmlDictionaryReader reader)
 1313        {
 01314            _hasExtension = true;
 01315            _extensionBuffer = EndpointAddress.ReadExtensions(reader, null, null, out EndpointIdentity identity, out int
 01316            if (_extensionBuffer != null)
 1317            {
 01318                _extensionBuffer.Close();
 1319            }
 01320            if (identity != null)
 1321            {
 01322                Identity = identity;
 1323            }
 01324        }
 1325
 1326        public EndpointAddress ToEndpointAddress()
 1327        {
 01328            return new EndpointAddress(
 01329                Uri,
 01330                Identity,
 01331                new AddressHeaderCollection(Headers),
 01332                GetReaderAtMetadata(),
 01333                GetReaderAtExtensions(),
 01334                _epr?.GetReaderAtPsp());
 1335        }
 1336    }
 1337}