< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.ReplyToHeader
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/Addressing.cs
Line coverage
83%
Covered lines: 30
Uncovered lines: 6
Coverable lines: 36
Total lines: 958
Line coverage: 83.3%
Branch coverage
83%
Covered branches: 15
Total branches: 18
Branch coverage: 83.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%11100%
Create(...)50%4460%
OnWriteHeaderContents(...)100%11100%
ReadHeader(...)90%101087.5%
ReadHeaderValue(...)100%11100%
.ctor(...)100%11100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/Addressing.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.Xml;
 6using CoreWCF.Runtime;
 7
 8namespace CoreWCF.Channels
 9{
 10    // TODO: This needed to be made public for NetTcp, investigate making it internal again
 11    public abstract class AddressingHeader : DictionaryHeader, IMessageHeaderWithSharedNamespace
 12    {
 13        protected AddressingHeader(AddressingVersion version)
 14        {
 15            Version = version;
 16        }
 17
 18        internal AddressingVersion Version { get; }
 19
 20        XmlDictionaryString IMessageHeaderWithSharedNamespace.SharedPrefix
 21        {
 22            get { return XD.AddressingDictionary.Prefix; }
 23        }
 24
 25        XmlDictionaryString IMessageHeaderWithSharedNamespace.SharedNamespace
 26        {
 27            get { return Version.DictionaryNamespace; }
 28        }
 29
 30        public override XmlDictionaryString DictionaryNamespace
 31        {
 32            get { return Version.DictionaryNamespace; }
 33        }
 34    }
 35
 36    internal class ActionHeader : AddressingHeader
 37    {
 38        private const bool mustUnderstandValue = true;
 39
 40        private ActionHeader(string action, AddressingVersion version)
 41            : base(version)
 42        {
 43            Action = action;
 44        }
 45
 46        public string Action { get; }
 47
 48        public override bool MustUnderstand
 49        {
 50            get { return mustUnderstandValue; }
 51        }
 52
 53        public override XmlDictionaryString DictionaryName
 54        {
 55            get { return XD.AddressingDictionary.Action; }
 56        }
 57
 58        public static ActionHeader Create(string action, AddressingVersion addressingVersion)
 59        {
 60            if (action == null)
 61            {
 62                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(action));
 63            }
 64
 65            if (addressingVersion == null)
 66            {
 67                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addressingVersion));
 68            }
 69
 70            return new ActionHeader(action, addressingVersion);
 71        }
 72
 73        public static ActionHeader Create(XmlDictionaryString dictionaryAction, AddressingVersion addressingVersion)
 74        {
 75            if (dictionaryAction == null)
 76            {
 77                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(Action));
 78            }
 79
 80            if (addressingVersion == null)
 81            {
 82                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addressingVersion));
 83            }
 84
 85            return new DictionaryActionHeader(dictionaryAction, addressingVersion);
 86        }
 87
 88        protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 89        {
 90            writer.WriteString(Action);
 91        }
 92
 93        public static string ReadHeaderValue(XmlDictionaryReader reader, AddressingVersion addressingVersion)
 94        {
 95            Fx.Assert(reader.IsStartElement(XD.AddressingDictionary.Action, addressingVersion.DictionaryNamespace), "");
 96            string act = reader.ReadElementContentAsString();
 97
 98            if (act.Length > 0 && (act[0] <= 32 || act[act.Length - 1] <= 32))
 99            {
 100                act = XmlUtil.Trim(act);
 101            }
 102
 103            return act;
 104        }
 105
 106        public static ActionHeader ReadHeader(XmlDictionaryReader reader, AddressingVersion version,
 107            string actor, bool mustUnderstand, bool relay)
 108        {
 109            string action = ReadHeaderValue(reader, version);
 110
 111            if (actor.Length == 0 && mustUnderstand == mustUnderstandValue && !relay)
 112            {
 113                return new ActionHeader(action, version);
 114            }
 115            else
 116            {
 117                return new FullActionHeader(action, actor, mustUnderstand, relay, version);
 118            }
 119        }
 120
 121        private class DictionaryActionHeader : ActionHeader
 122        {
 123            private readonly XmlDictionaryString _dictionaryAction;
 124
 125            public DictionaryActionHeader(XmlDictionaryString dictionaryAction, AddressingVersion version)
 126                : base(dictionaryAction.Value, version)
 127            {
 128                _dictionaryAction = dictionaryAction;
 129            }
 130
 131            protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 132            {
 133                writer.WriteString(_dictionaryAction);
 134            }
 135        }
 136
 137        private class FullActionHeader : ActionHeader
 138        {
 139            private readonly string _actor;
 140            private readonly bool _mustUnderstand;
 141            private readonly bool _relay;
 142
 143            public FullActionHeader(string action, string actor, bool mustUnderstand, bool relay, AddressingVersion vers
 144                : base(action, version)
 145            {
 146                _actor = actor;
 147                _mustUnderstand = mustUnderstand;
 148                _relay = relay;
 149            }
 150
 151            public override string Actor
 152            {
 153                get { return _actor; }
 154            }
 155
 156            public override bool MustUnderstand
 157            {
 158                get { return _mustUnderstand; }
 159            }
 160
 161            public override bool Relay
 162            {
 163                get { return _relay; }
 164            }
 165        }
 166    }
 167
 168    internal class FromHeader : AddressingHeader
 169    {
 170        private const bool mustUnderstandValue = false;
 171
 172        private FromHeader(EndpointAddress from, AddressingVersion version)
 173            : base(version)
 174        {
 175            From = from;
 176        }
 177
 178        public EndpointAddress From { get; }
 179
 180        public override XmlDictionaryString DictionaryName
 181        {
 182            get { return XD.AddressingDictionary.From; }
 183        }
 184
 185        public override bool MustUnderstand
 186        {
 187            get { return mustUnderstandValue; }
 188        }
 189
 190        public static FromHeader Create(EndpointAddress from, AddressingVersion addressingVersion)
 191        {
 192            if (from == null)
 193            {
 194                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(from));
 195            }
 196
 197            if (addressingVersion == null)
 198            {
 199                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addressingVersion));
 200            }
 201
 202            return new FromHeader(from, addressingVersion);
 203        }
 204
 205        protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 206        {
 207            From.WriteContentsTo(Version, writer);
 208        }
 209
 210        public static FromHeader ReadHeader(XmlDictionaryReader reader, AddressingVersion version,
 211            string actor, bool mustUnderstand, bool relay)
 212        {
 213            EndpointAddress from = ReadHeaderValue(reader, version);
 214
 215            if (actor.Length == 0 && mustUnderstand == mustUnderstandValue && !relay)
 216            {
 217                return new FromHeader(from, version);
 218            }
 219            else
 220            {
 221                return new FullFromHeader(from, actor, mustUnderstand, relay, version);
 222            }
 223        }
 224
 225        public static EndpointAddress ReadHeaderValue(XmlDictionaryReader reader, AddressingVersion addressingVersion)
 226        {
 227            Fx.Assert(reader.IsStartElement(XD.AddressingDictionary.From, addressingVersion.DictionaryNamespace), "");
 228            return EndpointAddress.ReadFrom(addressingVersion, reader);
 229        }
 230
 231        private class FullFromHeader : FromHeader
 232        {
 233            private readonly string _actor;
 234            private readonly bool _mustUnderstand;
 235            private readonly bool _relay;
 236
 237            public FullFromHeader(EndpointAddress from, string actor, bool mustUnderstand, bool relay, AddressingVersion
 238                : base(from, version)
 239            {
 240                _actor = actor;
 241                _mustUnderstand = mustUnderstand;
 242                _relay = relay;
 243            }
 244
 245            public override string Actor
 246            {
 247                get { return _actor; }
 248            }
 249
 250            public override bool MustUnderstand
 251            {
 252                get { return _mustUnderstand; }
 253            }
 254
 255            public override bool Relay
 256            {
 257                get { return _relay; }
 258            }
 259        }
 260    }
 261
 262    internal class FaultToHeader : AddressingHeader
 263    {
 264        private const bool mustUnderstandValue = false;
 265
 266        private FaultToHeader(EndpointAddress faultTo, AddressingVersion version)
 267            : base(version)
 268        {
 269            FaultTo = faultTo;
 270        }
 271
 272        public EndpointAddress FaultTo { get; }
 273
 274        public override XmlDictionaryString DictionaryName
 275        {
 276            get { return XD.AddressingDictionary.FaultTo; }
 277        }
 278
 279        public override bool MustUnderstand
 280        {
 281            get { return mustUnderstandValue; }
 282        }
 283
 284        protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 285        {
 286            FaultTo.WriteContentsTo(Version, writer);
 287        }
 288
 289        public static FaultToHeader Create(EndpointAddress faultTo, AddressingVersion addressingVersion)
 290        {
 291            if (faultTo == null)
 292            {
 293                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(faultTo));
 294            }
 295
 296            if (addressingVersion == null)
 297            {
 298                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addressingVersion));
 299            }
 300
 301            return new FaultToHeader(faultTo, addressingVersion);
 302        }
 303
 304        public static FaultToHeader ReadHeader(XmlDictionaryReader reader, AddressingVersion version,
 305            string actor, bool mustUnderstand, bool relay)
 306        {
 307            EndpointAddress faultTo = ReadHeaderValue(reader, version);
 308
 309            if (actor.Length == 0 && mustUnderstand == mustUnderstandValue && !relay)
 310            {
 311                return new FaultToHeader(faultTo, version);
 312            }
 313            else
 314            {
 315                return new FullFaultToHeader(faultTo, actor, mustUnderstand, relay, version);
 316            }
 317        }
 318
 319        public static EndpointAddress ReadHeaderValue(XmlDictionaryReader reader, AddressingVersion version)
 320        {
 321            Fx.Assert(reader.IsStartElement(XD.AddressingDictionary.FaultTo, version.DictionaryNamespace), "");
 322            return EndpointAddress.ReadFrom(version, reader);
 323        }
 324
 325        private class FullFaultToHeader : FaultToHeader
 326        {
 327            private readonly string _actor;
 328            private readonly bool _mustUnderstand;
 329            private readonly bool _relay;
 330
 331            public FullFaultToHeader(EndpointAddress faultTo, string actor, bool mustUnderstand, bool relay, AddressingV
 332                : base(faultTo, version)
 333            {
 334                _actor = actor;
 335                _mustUnderstand = mustUnderstand;
 336                _relay = relay;
 337            }
 338
 339            public override string Actor
 340            {
 341                get { return _actor; }
 342            }
 343
 344            public override bool MustUnderstand
 345            {
 346                get { return _mustUnderstand; }
 347            }
 348
 349            public override bool Relay
 350            {
 351                get { return _relay; }
 352            }
 353        }
 354    }
 355
 356    // TODO: This needed to be made public for NetTcp, investigate making it internal again
 357    public class ToHeader : AddressingHeader
 358    {
 359        private const bool mustUnderstandValue = true;
 360        private static ToHeader s_anonymousToHeader10;
 361        private static ToHeader s_anonymousToHeader200408;
 362
 363        protected ToHeader(Uri to, AddressingVersion version)
 364            : base(version)
 365        {
 366            To = to;
 367        }
 368
 369        private static ToHeader AnonymousTo10
 370        {
 371            get
 372            {
 373                if (s_anonymousToHeader10 == null)
 374                {
 375                    s_anonymousToHeader10 = new AnonymousToHeader(AddressingVersion.WSAddressing10);
 376                }
 377
 378                return s_anonymousToHeader10;
 379            }
 380        }
 381
 382        static ToHeader AnonymousTo200408
 383        {
 384            get
 385            {
 386                if (s_anonymousToHeader200408 == null)
 387                    s_anonymousToHeader200408 = new AnonymousToHeader(AddressingVersion.WSAddressingAugust2004);
 388                return s_anonymousToHeader200408;
 389            }
 390        }
 391
 392        public override XmlDictionaryString DictionaryName
 393        {
 394            get { return XD.AddressingDictionary.To; }
 395        }
 396
 397        public override bool MustUnderstand
 398        {
 399            get { return mustUnderstandValue; }
 400        }
 401
 402        public Uri To { get; }
 403
 404        public static ToHeader Create(Uri toUri, XmlDictionaryString dictionaryTo, AddressingVersion addressingVersion)
 405        {
 406            if (addressingVersion == null)
 407            {
 408                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addressingVersion));
 409            }
 410
 411            if (((object)toUri == (object)addressingVersion.AnonymousUri))
 412            {
 413                if (addressingVersion == AddressingVersion.WSAddressing10)
 414                {
 415                    return AnonymousTo10;
 416                }
 417                else
 418                {
 419                    return AnonymousTo200408;
 420                }
 421            }
 422            else
 423            {
 424                return new DictionaryToHeader(toUri, dictionaryTo, addressingVersion);
 425            }
 426        }
 427
 428        public static ToHeader Create(Uri to, AddressingVersion addressingVersion)
 429        {
 430            if ((object)to == null)
 431            {
 432                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(to));
 433            }
 434            else if ((object)to == addressingVersion.AnonymousUri)
 435            {
 436                if (addressingVersion == AddressingVersion.WSAddressing10)
 437                {
 438                    return AnonymousTo10;
 439                }
 440                else
 441                {
 442                    return AnonymousTo200408;
 443                }
 444            }
 445            else
 446            {
 447                return new ToHeader(to, addressingVersion);
 448            }
 449        }
 450
 451        protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 452        {
 453            writer.WriteString(To.AbsoluteUri);
 454        }
 455
 456        public static Uri ReadHeaderValue(XmlDictionaryReader reader, AddressingVersion version)
 457        {
 458            return ReadHeaderValue(reader, version, null);
 459        }
 460
 461        internal static Uri ReadHeaderValue(XmlDictionaryReader reader, AddressingVersion version, UriCache uriCache)
 462        {
 463            Fx.Assert(reader.IsStartElement(XD.AddressingDictionary.To, version.DictionaryNamespace), "");
 464
 465            string toString = reader.ReadElementContentAsString();
 466
 467            if ((object)toString == (object)version.Anonymous)
 468            {
 469                return version.AnonymousUri;
 470            }
 471
 472            if (uriCache == null)
 473            {
 474                return new Uri(toString);
 475            }
 476
 477            return uriCache.CreateUri(toString);
 478        }
 479
 480        internal static ToHeader ReadHeader(XmlDictionaryReader reader, AddressingVersion version, UriCache uriCache,
 481            string actor, bool mustUnderstand, bool relay)
 482        {
 483            Uri to = ReadHeaderValue(reader, version, uriCache);
 484
 485            if (actor.Length == 0 && mustUnderstand == mustUnderstandValue && !relay)
 486            {
 487                if ((object)to == (object)version.AnonymousUri)
 488                {
 489                    if (version == AddressingVersion.WSAddressing10)
 490                    {
 491                        return AnonymousTo10;
 492                    }
 493                    else
 494                    {
 495                        throw new PlatformNotSupportedException($"Unsupported addressing version {version}");
 496                    }
 497                    //return AnonymousTo200408;
 498                }
 499                else
 500                {
 501                    return new ToHeader(to, version);
 502                }
 503            }
 504            else
 505            {
 506                return new FullToHeader(to, actor, mustUnderstand, relay, version);
 507            }
 508        }
 509
 510        private class AnonymousToHeader : ToHeader
 511        {
 512            public AnonymousToHeader(AddressingVersion version)
 513                : base(version.AnonymousUri, version)
 514            {
 515            }
 516
 517            protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 518            {
 519                writer.WriteString(Version.DictionaryAnonymous);
 520            }
 521        }
 522
 523        private class DictionaryToHeader : ToHeader
 524        {
 525            private readonly XmlDictionaryString _dictionaryTo;
 526
 527            public DictionaryToHeader(Uri to, XmlDictionaryString dictionaryTo, AddressingVersion version)
 528                : base(to, version)
 529            {
 530                _dictionaryTo = dictionaryTo;
 531            }
 532
 533            protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 534            {
 535                writer.WriteString(_dictionaryTo);
 536            }
 537        }
 538
 539        private class FullToHeader : ToHeader
 540        {
 541            private readonly string _actor;
 542            private readonly bool _mustUnderstand;
 543            private readonly bool _relay;
 544
 545            public FullToHeader(Uri to, string actor, bool mustUnderstand, bool relay, AddressingVersion version)
 546                : base(to, version)
 547            {
 548                _actor = actor;
 549                _mustUnderstand = mustUnderstand;
 550                _relay = relay;
 551            }
 552
 553            public override string Actor
 554            {
 555                get { return _actor; }
 556            }
 557
 558            public override bool MustUnderstand
 559            {
 560                get { return _mustUnderstand; }
 561            }
 562
 563            public override bool Relay
 564            {
 565                get { return _relay; }
 566            }
 567        }
 568    }
 569
 570    internal class ReplyToHeader : AddressingHeader
 571    {
 572        private const bool mustUnderstandValue = false;
 573        private static ReplyToHeader s_anonymousReplyToHeader10;
 574        private static ReplyToHeader s_anonymousReplyToHeader200408;
 575
 576        private ReplyToHeader(EndpointAddress replyTo, AddressingVersion version)
 7577            : base(version)
 578        {
 7579            ReplyTo = replyTo;
 7580        }
 581
 177582        public EndpointAddress ReplyTo { get; }
 583
 584        public override XmlDictionaryString DictionaryName
 585        {
 110586            get { return XD.AddressingDictionary.ReplyTo; }
 587        }
 588
 589        public override bool MustUnderstand
 590        {
 70591            get { return mustUnderstandValue; }
 592        }
 593
 594        public static ReplyToHeader AnonymousReplyTo10
 595        {
 596            get
 597            {
 191598                if (s_anonymousReplyToHeader10 == null)
 599                {
 3600                    s_anonymousReplyToHeader10 = new ReplyToHeader(EndpointAddress.AnonymousAddress, AddressingVersion.W
 601                }
 602
 191603                return s_anonymousReplyToHeader10;
 604            }
 605        }
 606
 607        public static ReplyToHeader AnonymousReplyTo200408
 608        {
 609            get
 610            {
 6611                if (s_anonymousReplyToHeader200408 == null)
 2612                    s_anonymousReplyToHeader200408 = new ReplyToHeader(EndpointAddress.AnonymousAddress, AddressingVersi
 6613                return s_anonymousReplyToHeader200408;
 614            }
 615        }
 616
 617        public static ReplyToHeader Create(EndpointAddress replyTo, AddressingVersion addressingVersion)
 618        {
 1619            if (replyTo == null)
 620            {
 0621                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(replyTo));
 622            }
 623
 1624            if (addressingVersion == null)
 625            {
 0626                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addressingVersion));
 627            }
 628
 1629            return new ReplyToHeader(replyTo, addressingVersion);
 630        }
 631
 632        protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 633        {
 1634            ReplyTo.WriteContentsTo(Version, writer);
 1635        }
 636
 637        public static ReplyToHeader ReadHeader(XmlDictionaryReader reader, AddressingVersion version,
 638            string actor, bool mustUnderstand, bool relay)
 639        {
 130640            EndpointAddress replyTo = ReadHeaderValue(reader, version);
 641
 130642            if (actor.Length == 0 && mustUnderstand == mustUnderstandValue && !relay)
 643            {
 129644                if ((object)replyTo == EndpointAddress.AnonymousAddress)
 645                {
 129646                    if (version == AddressingVersion.WSAddressing10)
 647                    {
 123648                        return AnonymousReplyTo10;
 649                    }
 650                    else
 651                    {
 6652                        return AnonymousReplyTo200408;
 653                    }
 654                }
 0655                return new ReplyToHeader(replyTo, version);
 656            }
 657            else
 658            {
 1659                return new FullReplyToHeader(replyTo, actor, mustUnderstand, relay, version);
 660            }
 661        }
 662
 663        public static EndpointAddress ReadHeaderValue(XmlDictionaryReader reader, AddressingVersion version)
 664        {
 665            Fx.Assert(reader.IsStartElement(XD.AddressingDictionary.ReplyTo, version.DictionaryNamespace), "");
 278666            return EndpointAddress.ReadFrom(version, reader);
 667        }
 668
 669        private class FullReplyToHeader : ReplyToHeader
 670        {
 671            private readonly string _actor;
 672            private readonly bool _mustUnderstand;
 673            private readonly bool _relay;
 674
 675            public FullReplyToHeader(EndpointAddress replyTo, string actor, bool mustUnderstand, bool relay, AddressingV
 1676                : base(replyTo, version)
 677            {
 1678                _actor = actor;
 1679                _mustUnderstand = mustUnderstand;
 1680                _relay = relay;
 1681            }
 682
 683            public override string Actor
 684            {
 0685                get { return _actor; }
 686            }
 687
 688            public override bool MustUnderstand
 689            {
 0690                get { return _mustUnderstand; }
 691            }
 692
 693            public override bool Relay
 694            {
 0695                get { return _relay; }
 696            }
 697        }
 698    }
 699
 700    internal class MessageIDHeader : AddressingHeader
 701    {
 702        private const bool mustUnderstandValue = false;
 703
 704        private MessageIDHeader(UniqueId messageId, AddressingVersion version)
 705            : base(version)
 706        {
 707            MessageId = messageId;
 708        }
 709
 710        public override XmlDictionaryString DictionaryName
 711        {
 712            get { return XD.AddressingDictionary.MessageId; }
 713        }
 714
 715        public UniqueId MessageId { get; }
 716
 717        public override bool MustUnderstand
 718        {
 719            get { return mustUnderstandValue; }
 720        }
 721
 722        public static MessageIDHeader Create(UniqueId messageId, AddressingVersion addressingVersion)
 723        {
 724            if (ReferenceEquals(messageId, null))
 725            {
 726                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(messageId));
 727            }
 728
 729            if (addressingVersion == null)
 730            {
 731                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addressingVersion));
 732            }
 733
 734            return new MessageIDHeader(messageId, addressingVersion);
 735        }
 736
 737        protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 738        {
 739            writer.WriteValue(MessageId);
 740        }
 741
 742        public static UniqueId ReadHeaderValue(XmlDictionaryReader reader, AddressingVersion version)
 743        {
 744            Fx.Assert(reader.IsStartElement(XD.AddressingDictionary.MessageId, version.DictionaryNamespace), "");
 745            return reader.ReadElementContentAsUniqueId();
 746        }
 747
 748        public static MessageIDHeader ReadHeader(XmlDictionaryReader reader, AddressingVersion version,
 749            string actor, bool mustUnderstand, bool relay)
 750        {
 751            UniqueId messageId = ReadHeaderValue(reader, version);
 752
 753            if (actor.Length == 0 && mustUnderstand == mustUnderstandValue && !relay)
 754            {
 755                return new MessageIDHeader(messageId, version);
 756            }
 757            else
 758            {
 759                return new FullMessageIDHeader(messageId, actor, mustUnderstand, relay, version);
 760            }
 761        }
 762
 763        private class FullMessageIDHeader : MessageIDHeader
 764        {
 765            private readonly string _actor;
 766            private readonly bool _mustUnderstand;
 767            private readonly bool _relay;
 768
 769            public FullMessageIDHeader(UniqueId messageId, string actor, bool mustUnderstand, bool relay, AddressingVers
 770                : base(messageId, version)
 771            {
 772                _actor = actor;
 773                _mustUnderstand = mustUnderstand;
 774                _relay = relay;
 775            }
 776
 777            public override string Actor
 778            {
 779                get { return _actor; }
 780            }
 781
 782            public override bool MustUnderstand
 783            {
 784                get { return _mustUnderstand; }
 785            }
 786
 787            public override bool Relay
 788            {
 789                get { return _relay; }
 790            }
 791        }
 792    }
 793
 794    internal class RelatesToHeader : AddressingHeader
 795    {
 796        private const bool mustUnderstandValue = false;
 797        internal static readonly Uri ReplyRelationshipType = new Uri(Addressing10Strings.ReplyRelationship);
 798
 799        private RelatesToHeader(UniqueId messageId, AddressingVersion version)
 800            : base(version)
 801        {
 802            UniqueId = messageId;
 803        }
 804
 805        public override XmlDictionaryString DictionaryName
 806        {
 807            get { return XD.AddressingDictionary.RelatesTo; }
 808        }
 809
 810        public UniqueId UniqueId { get; }
 811
 812        public override bool MustUnderstand
 813        {
 814            get { return mustUnderstandValue; }
 815        }
 816
 817        public virtual Uri RelationshipType
 818        {
 819            get { return ReplyRelationshipType; }
 820        }
 821
 822        public static RelatesToHeader Create(UniqueId messageId, AddressingVersion addressingVersion)
 823        {
 824            if (ReferenceEquals(messageId, null))
 825            {
 826                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(messageId));
 827            }
 828
 829            if (addressingVersion == null)
 830            {
 831                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addressingVersion));
 832            }
 833
 834            return new RelatesToHeader(messageId, addressingVersion);
 835        }
 836
 837        public static RelatesToHeader Create(UniqueId messageId, AddressingVersion addressingVersion, Uri relationshipTy
 838        {
 839            if (ReferenceEquals(messageId, null))
 840            {
 841                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(messageId));
 842            }
 843
 844            if (addressingVersion == null)
 845            {
 846                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addressingVersion));
 847            }
 848
 849            if (relationshipType == null)
 850            {
 851                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(relationshipType));
 852            }
 853
 854            if (relationshipType == ReplyRelationshipType)
 855            {
 856                return new RelatesToHeader(messageId, addressingVersion);
 857            }
 858            else
 859            {
 860                return new FullRelatesToHeader(messageId, "", false, false, addressingVersion);
 861            }
 862        }
 863
 864        protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 865        {
 866            writer.WriteValue(UniqueId);
 867        }
 868
 869        public static void ReadHeaderValue(XmlDictionaryReader reader, AddressingVersion version, out Uri relationshipTy
 870        {
 871            AddressingDictionary addressingDictionary = XD.AddressingDictionary;
 872
 873            // The RelationshipType attribute has no namespace.
 874            relationshipType = ReplyRelationshipType;
 875            /*
 876            string relation = reader.GetAttribute(addressingDictionary.RelationshipType, addressingDictionary.Empty);
 877            if (relation == null)
 878            {
 879                relationshipType = ReplyRelationshipType;
 880            }
 881            else
 882            {
 883                relationshipType = new Uri(relation);
 884            }
 885            */
 886            Fx.Assert(reader.IsStartElement(addressingDictionary.RelatesTo, version.DictionaryNamespace), "");
 887            messageId = reader.ReadElementContentAsUniqueId();
 888        }
 889
 890        public static RelatesToHeader ReadHeader(XmlDictionaryReader reader, AddressingVersion version,
 891            string actor, bool mustUnderstand, bool relay)
 892        {
 893            ReadHeaderValue(reader, version, out Uri relationship, out UniqueId messageId);
 894
 895            if (actor.Length == 0 && mustUnderstand == mustUnderstandValue && !relay && (object)relationship == (object)
 896            {
 897                return new RelatesToHeader(messageId, version);
 898            }
 899            else
 900            {
 901                return new FullRelatesToHeader(messageId, actor, mustUnderstand, relay, version);
 902            }
 903        }
 904
 905        private class FullRelatesToHeader : RelatesToHeader
 906        {
 907            private readonly string _actor;
 908            private readonly bool _mustUnderstand;
 909            private readonly bool _relay;
 910            //Uri relationship;
 911
 912            public FullRelatesToHeader(UniqueId messageId, string actor, bool mustUnderstand, bool relay, AddressingVers
 913                : base(messageId, version)
 914            {
 915                //this.relationship = relationship;
 916                _actor = actor;
 917                _mustUnderstand = mustUnderstand;
 918                _relay = relay;
 919            }
 920
 921            public override string Actor
 922            {
 923                get { return _actor; }
 924            }
 925
 926            public override bool MustUnderstand
 927            {
 928                get { return _mustUnderstand; }
 929            }
 930
 931            /*
 932            public override Uri RelationshipType
 933            {
 934                get { return relationship; }
 935            }
 936            */
 937
 938            public override bool Relay
 939            {
 940                get { return _relay; }
 941            }
 942
 943            protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 944            {
 945                /*
 946                if ((object)relationship != (object)ReplyRelationshipType)
 947                {
 948                    // The RelationshipType attribute has no namespace.
 949                    writer.WriteStartAttribute(AddressingStrings.RelationshipType, AddressingStrings.Empty);
 950                    writer.WriteString(relationship.AbsoluteUri);
 951                    writer.WriteEndAttribute();
 952                }
 953                */
 954                writer.WriteValue(UniqueId);
 955            }
 956        }
 957    }
 958}