< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Channels.ReceivedFault
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/MessageFault.cs
Line coverage
48%
Covered lines: 57
Uncovered lines: 61
Coverable lines: 118
Total lines: 740
Line coverage: 48.3%
Branch coverage
34%
Covered branches: 15
Total branches: 44
Branch coverage: 34%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)50%22100%
InferHasDetail(...)100%66100%
OnWriteDetail(...)0%660%
OnWriteStartDetail(...)0%440%
OnWriteDetailContents(...)0%220%
OnGetReaderAtDetailContents()100%11100%
ShouldWriteDetailAttribute(...)0%880%
CreateFaultNone(...)100%110%
CreateFault12Driver(...)70%101088.88%
ReadFaultCode12Driver(...)50%2255.55%
CreateFault12(...)100%11100%
ReadTranslation12(...)100%11100%
CreateFault11(...)0%440%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Channels/MessageFault.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.Globalization;
 7using System.Runtime.Serialization;
 8using System.Xml;
 9using CoreWCF.Diagnostics;
 10using CoreWCF.Dispatcher;
 11
 12namespace CoreWCF.Channels
 13{
 14    public abstract class MessageFault
 15    {
 16        internal static MessageFault CreateFault(FaultCode code, string reason)
 17        {
 18            return CreateFault(code, new FaultReason(reason));
 19        }
 20
 21        internal static MessageFault CreateFault(FaultCode code, FaultReason reason)
 22        {
 23            return CreateFault(code, reason, null, null, "", "");
 24        }
 25
 26        internal static MessageFault CreateFault(FaultCode code, FaultReason reason, object detail)
 27        {
 28            return CreateFault(code, reason, detail, DataContractSerializerDefaults.CreateSerializer(
 29                (detail == null ? typeof(object) : detail.GetType()), int.MaxValue/*maxItems*/), "", "");
 30        }
 31
 32        public static MessageFault CreateFault(FaultCode code, FaultReason reason, object detail, XmlObjectSerializer se
 33        {
 34            if (code == null)
 35            {
 36                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(code));
 37            }
 38
 39            if (reason == null)
 40            {
 41                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(reason));
 42            }
 43
 44            if (actor == null)
 45            {
 46                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(actor));
 47            }
 48
 49            if (node == null)
 50            {
 51                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(node));
 52            }
 53
 54            return new XmlObjectSerializerFault(code, reason, detail, serializer, actor, node);
 55        }
 56
 57        public static MessageFault CreateFault(Message message, int maxBufferSize)
 58        {
 59            if (message == null)
 60            {
 61                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(message));
 62            }
 63
 64            XmlDictionaryReader reader = message.GetReaderAtBodyContents();
 65            using (reader)
 66            {
 67                try
 68                {
 69                    EnvelopeVersion envelopeVersion = message.Version.Envelope;
 70                    MessageFault fault;
 71                    if (envelopeVersion == EnvelopeVersion.Soap12)
 72                    {
 73                        fault = ReceivedFault.CreateFault12(reader, maxBufferSize);
 74                    }
 75                    else if (envelopeVersion == EnvelopeVersion.Soap11)
 76                    {
 77                        fault = ReceivedFault.CreateFault11(reader, maxBufferSize);
 78                    }
 79                    else if (envelopeVersion == EnvelopeVersion.None)
 80                    {
 81                        fault = ReceivedFault.CreateFaultNone(reader, maxBufferSize);
 82                    }
 83                    else
 84                    {
 85                        throw TraceUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.EnvelopeVersionUn
 86                    }
 87                    message.ReadFromBodyContentsToEnd(reader);
 88                    return fault;
 89                }
 90                catch (InvalidOperationException e)
 91                {
 92                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
 93                        SR.SFxErrorDeserializingFault, e));
 94                }
 95                catch (FormatException e)
 96                {
 97                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
 98                        SR.SFxErrorDeserializingFault, e));
 99                }
 100                catch (XmlException e)
 101                {
 102                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
 103                        SR.SFxErrorDeserializingFault, e));
 104                }
 105            }
 106        }
 107
 108        public virtual string Actor
 109        {
 110            get
 111            {
 112                return "";
 113            }
 114        }
 115
 116        public abstract FaultCode Code { get; }
 117        public virtual string Node
 118        {
 119            get
 120            {
 121                return "";
 122            }
 123        }
 124
 125        public abstract bool HasDetail { get; }
 126
 127        public abstract FaultReason Reason { get; }
 128
 129        public T GetDetail<T>()
 130        {
 131            return GetDetail<T>(DataContractSerializerDefaults.CreateSerializer(typeof(T), int.MaxValue/*maxItems*/));
 132        }
 133
 134        public T GetDetail<T>(XmlObjectSerializer serializer)
 135        {
 136            if (serializer == null)
 137            {
 138                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(serializer));
 139            }
 140
 141            XmlDictionaryReader reader = GetReaderAtDetailContents();
 142            T value = (T)serializer.ReadObject(reader);
 143            if (!reader.EOF)
 144            {
 145                reader.MoveToContent();
 146                if (reader.NodeType != XmlNodeType.EndElement && !reader.EOF)
 147                {
 148                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.ExtraContentIsPrese
 149                }
 150            }
 151            return value;
 152        }
 153
 154        public XmlDictionaryReader GetReaderAtDetailContents()
 155        {
 156            if (!HasDetail)
 157            {
 158                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.FaultDoesNotH
 159            }
 160
 161            return OnGetReaderAtDetailContents();
 162        }
 163
 164        protected virtual void OnWriteDetail(XmlDictionaryWriter writer, EnvelopeVersion version)
 165        {
 166            OnWriteStartDetail(writer, version);
 167            OnWriteDetailContents(writer);
 168            writer.WriteEndElement();
 169        }
 170
 171        protected virtual void OnWriteStartDetail(XmlDictionaryWriter writer, EnvelopeVersion version)
 172        {
 173            if (version == EnvelopeVersion.Soap12)
 174            {
 175                writer.WriteStartElement(XD.Message12Dictionary.FaultDetail, XD.Message12Dictionary.Namespace);
 176            }
 177            else if (version == EnvelopeVersion.Soap11)
 178            {
 179                writer.WriteStartElement(XD.Message11Dictionary.FaultDetail, XD.Message11Dictionary.FaultNamespace);
 180            }
 181            else
 182            {
 183                writer.WriteStartElement(XD.Message12Dictionary.FaultDetail, XD.MessageDictionary.Namespace);
 184            }
 185        }
 186
 187        protected abstract void OnWriteDetailContents(XmlDictionaryWriter writer);
 188
 189        protected virtual XmlDictionaryReader OnGetReaderAtDetailContents()
 190        {
 191            XmlBuffer detailBuffer = new XmlBuffer(int.MaxValue);
 192            XmlDictionaryWriter writer = detailBuffer.OpenSection(XmlDictionaryReaderQuotas.Max);
 193            OnWriteDetail(writer, EnvelopeVersion.Soap12);  // Wrap in soap 1.2 by default
 194            detailBuffer.CloseSection();
 195            detailBuffer.Close();
 196            XmlDictionaryReader reader = detailBuffer.GetReader(0);
 197            reader.Read(); // Skip the detail element
 198            return reader;
 199        }
 200
 201        internal void WriteTo(XmlWriter writer, EnvelopeVersion version)
 202        {
 203            WriteTo(XmlDictionaryWriter.CreateDictionaryWriter(writer), version);
 204        }
 205
 206        internal void WriteTo(XmlDictionaryWriter writer, EnvelopeVersion version)
 207        {
 208            if (writer == null)
 209            {
 210                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(writer));
 211            }
 212
 213            if (version == null)
 214            {
 215                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(version));
 216            }
 217
 218            if (version == EnvelopeVersion.Soap12)
 219            {
 220                WriteTo12(writer);
 221            }
 222            else if (version == EnvelopeVersion.Soap11)
 223            {
 224                WriteTo11(writer);
 225            }
 226            else if (version == EnvelopeVersion.None)
 227            {
 228                WriteToNone(writer);
 229            }
 230            else
 231            {
 232                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.Env
 233            }
 234        }
 235
 236        private void WriteToNone(XmlDictionaryWriter writer)
 237        {
 238            WriteTo12Driver(writer, EnvelopeVersion.None);
 239        }
 240
 241        private void WriteTo12Driver(XmlDictionaryWriter writer, EnvelopeVersion version)
 242        {
 243            writer.WriteStartElement(XD.MessageDictionary.Fault, version.DictionaryNamespace);
 244            writer.WriteStartElement(XD.Message12Dictionary.FaultCode, version.DictionaryNamespace);
 245            WriteFaultCode12Driver(writer, Code, version);
 246            writer.WriteEndElement();
 247            writer.WriteStartElement(XD.Message12Dictionary.FaultReason, version.DictionaryNamespace);
 248            FaultReason reason = Reason;
 249            for (int i = 0; i < reason.Translations.Count; i++)
 250            {
 251                FaultReasonText text = reason.Translations[i];
 252                writer.WriteStartElement(XD.Message12Dictionary.FaultText, version.DictionaryNamespace);
 253                writer.WriteAttributeString("xml", "lang", XmlUtil.XmlNs, text.XmlLang);
 254                writer.WriteString(text.Text);
 255                writer.WriteEndElement();
 256            }
 257            writer.WriteEndElement();
 258            if (Node.Length > 0)
 259            {
 260                writer.WriteElementString(XD.Message12Dictionary.FaultNode, version.DictionaryNamespace, Node);
 261            }
 262
 263            if (Actor.Length > 0)
 264            {
 265                writer.WriteElementString(XD.Message12Dictionary.FaultRole, version.DictionaryNamespace, Actor);
 266            }
 267
 268            if (HasDetail)
 269            {
 270                OnWriteDetail(writer, version);
 271            }
 272            writer.WriteEndElement();
 273        }
 274
 275        private void WriteFaultCode12Driver(XmlDictionaryWriter writer, FaultCode faultCode, EnvelopeVersion version)
 276        {
 277            writer.WriteStartElement(XD.Message12Dictionary.FaultValue, version.DictionaryNamespace);
 278            string name;
 279            if (faultCode.IsSenderFault)
 280            {
 281                name = version.SenderFaultName;
 282            }
 283            else if (faultCode.IsReceiverFault)
 284            {
 285                name = version.ReceiverFaultName;
 286            }
 287            else
 288            {
 289                name = faultCode.Name;
 290            }
 291
 292            string ns;
 293            if (faultCode.IsPredefinedFault)
 294            {
 295                ns = version.Namespace;
 296            }
 297            else
 298            {
 299                ns = faultCode.Namespace;
 300            }
 301
 302            string prefix = writer.LookupPrefix(ns);
 303            if (prefix == null)
 304            {
 305                writer.WriteAttributeString("xmlns", "a", XmlUtil.XmlNsNs, ns);
 306            }
 307
 308            writer.WriteQualifiedName(name, ns);
 309            writer.WriteEndElement();
 310
 311            if (faultCode.SubCode != null)
 312            {
 313                writer.WriteStartElement(XD.Message12Dictionary.FaultSubcode, version.DictionaryNamespace);
 314                WriteFaultCode12Driver(writer, faultCode.SubCode, version);
 315                writer.WriteEndElement();
 316            }
 317        }
 318
 319        private void WriteTo12(XmlDictionaryWriter writer)
 320        {
 321            WriteTo12Driver(writer, EnvelopeVersion.Soap12);
 322        }
 323
 324        private void WriteTo11(XmlDictionaryWriter writer)
 325        {
 326            writer.WriteStartElement(XD.MessageDictionary.Fault, XD.Message11Dictionary.Namespace);
 327            writer.WriteStartElement(XD.Message11Dictionary.FaultCode, XD.Message11Dictionary.FaultNamespace);
 328
 329            FaultCode faultCode = Code;
 330            if (faultCode.SubCode != null)
 331            {
 332                faultCode = faultCode.SubCode;
 333            }
 334
 335            string name;
 336            if (faultCode.IsSenderFault)
 337            {
 338                name = "Client";
 339            }
 340            else if (faultCode.IsReceiverFault)
 341            {
 342                name = "Server";
 343            }
 344            else
 345            {
 346                name = faultCode.Name;
 347            }
 348
 349            string ns;
 350            if (faultCode.IsPredefinedFault)
 351            {
 352                ns = Message11Strings.Namespace;
 353            }
 354            else
 355            {
 356                ns = faultCode.Namespace;
 357            }
 358
 359            string prefix = writer.LookupPrefix(ns);
 360            if (prefix == null)
 361            {
 362                writer.WriteAttributeString("xmlns", "a", XmlUtil.XmlNsNs, ns);
 363            }
 364
 365            writer.WriteQualifiedName(name, ns);
 366            writer.WriteEndElement();
 367            FaultReasonText translation = Reason.Translations[0];
 368            writer.WriteStartElement(XD.Message11Dictionary.FaultString, XD.Message11Dictionary.FaultNamespace);
 369            if (translation.XmlLang.Length > 0)
 370            {
 371                writer.WriteAttributeString("xml", "lang", XmlUtil.XmlNs, translation.XmlLang);
 372            }
 373
 374            writer.WriteString(translation.Text);
 375            writer.WriteEndElement();
 376            if (Actor.Length > 0)
 377            {
 378                writer.WriteElementString(XD.Message11Dictionary.FaultActor, XD.Message11Dictionary.FaultNamespace, Acto
 379            }
 380
 381            if (HasDetail)
 382            {
 383                OnWriteDetail(writer, EnvelopeVersion.Soap11);
 384            }
 385            writer.WriteEndElement();
 386        }
 387    }
 388
 389    internal class XmlObjectSerializerFault : MessageFault
 390    {
 391        private readonly FaultCode _code;
 392        private readonly FaultReason _reason;
 393        private readonly string _actor;
 394        private readonly string _node;
 395        private readonly object _detail;
 396        private readonly XmlObjectSerializer _serializer;
 397
 398        public XmlObjectSerializerFault(FaultCode code, FaultReason reason, object detail, XmlObjectSerializer serialize
 399        {
 400            _code = code;
 401            _reason = reason;
 402            _detail = detail;
 403            _serializer = serializer;
 404            _actor = actor;
 405            _node = node;
 406        }
 407
 408        public override string Actor
 409        {
 410            get
 411            {
 412                return _actor;
 413            }
 414        }
 415
 416        public override FaultCode Code
 417        {
 418            get
 419            {
 420                return _code;
 421            }
 422        }
 423
 424        public override bool HasDetail
 425        {
 426            get
 427            {
 428                return _serializer != null;
 429            }
 430        }
 431
 432        public override string Node
 433        {
 434            get
 435            {
 436                return _node;
 437            }
 438        }
 439
 440        public override FaultReason Reason
 441        {
 442            get
 443            {
 444                return _reason;
 445            }
 446        }
 447
 448        private object ThisLock
 449        {
 450            get
 451            {
 452                return _code;
 453            }
 454        }
 455
 456        protected override void OnWriteDetailContents(XmlDictionaryWriter writer)
 457        {
 458            if (_serializer != null)
 459            {
 460                lock (ThisLock)
 461                {
 462                    _serializer.WriteObject(writer, _detail);
 463                }
 464            }
 465        }
 466    }
 467
 468    internal class ReceivedFault : MessageFault
 469    {
 470        private readonly FaultCode _code;
 471        private readonly FaultReason _reason;
 472        private readonly string _actor;
 473        private readonly string _node;
 474        private readonly XmlBuffer _detail;
 475        private readonly bool _hasDetail;
 476        private readonly EnvelopeVersion _receivedVersion;
 477
 2478        private ReceivedFault(FaultCode code, FaultReason reason, string actor, string node, XmlBuffer detail, EnvelopeV
 479        {
 2480            _code = code;
 2481            _reason = reason;
 2482            _actor = actor;
 2483            _node = node;
 2484            _receivedVersion = version;
 2485            _hasDetail = InferHasDetail(detail);
 2486            _detail = _hasDetail ? detail : null;
 2487        }
 488
 489        public override string Actor
 490        {
 491            get
 492            {
 2493                return _actor;
 494            }
 495        }
 496
 497        public override FaultCode Code
 498        {
 499            get
 500            {
 2501                return _code;
 502            }
 503        }
 504
 505        public override bool HasDetail
 506        {
 507            get
 508            {
 4509                return _hasDetail;
 510            }
 511        }
 512
 513        public override string Node
 514        {
 515            get
 516            {
 2517                return _node;
 518            }
 519        }
 520
 521        public override FaultReason Reason
 522        {
 523            get
 524            {
 2525                return _reason;
 526            }
 527        }
 528
 529        private bool InferHasDetail(XmlBuffer detail)
 530        {
 2531            bool hasDetail = false;
 2532            if (detail != null)
 533            {
 2534                XmlDictionaryReader reader = detail.GetReader(0);
 2535                if (!reader.IsEmptyElement && reader.Read()) // check if the detail element contains data
 536                {
 2537                    hasDetail = (reader.MoveToContent() != XmlNodeType.EndElement);
 538                }
 539
 2540                reader.Dispose();
 541            }
 2542            return hasDetail;
 543        }
 544
 545        protected override void OnWriteDetail(XmlDictionaryWriter writer, EnvelopeVersion version)
 546        {
 0547            using (XmlReader r = _detail.GetReader(0))
 548            {
 549                // Start the element
 0550                base.OnWriteStartDetail(writer, version);
 551
 552                // Copy the attributes
 0553                while (r.MoveToNextAttribute())
 554                {
 0555                    if (ShouldWriteDetailAttribute(version, r.Prefix, r.LocalName, r.Value))
 556                    {
 0557                        writer.WriteAttributeString(r.Prefix, r.LocalName, r.NamespaceURI, r.Value);
 558                    }
 559                }
 0560                r.MoveToElement();
 561
 0562                r.Read();
 563
 564                // Copy the contents
 0565                while (r.NodeType != XmlNodeType.EndElement)
 566                {
 0567                    writer.WriteNode(r, false);
 568                }
 569
 570                // End the element
 0571                writer.WriteEndElement();
 0572            }
 0573        }
 574
 575        protected override void OnWriteStartDetail(XmlDictionaryWriter writer, EnvelopeVersion version)
 576        {
 0577            using (XmlReader r = _detail.GetReader(0))
 578            {
 579                // Start the element
 0580                base.OnWriteStartDetail(writer, version);
 581
 582                // Copy the attributes
 0583                while (r.MoveToNextAttribute())
 584                {
 0585                    if (ShouldWriteDetailAttribute(version, r.Prefix, r.LocalName, r.Value))
 586                    {
 0587                        writer.WriteAttributeString(r.Prefix, r.LocalName, r.NamespaceURI, r.Value);
 588                    }
 589                }
 0590            }
 0591        }
 592
 593        protected override void OnWriteDetailContents(XmlDictionaryWriter writer)
 594        {
 0595            using (XmlReader r = _detail.GetReader(0))
 596            {
 0597                r.Read();
 0598                while (r.NodeType != XmlNodeType.EndElement)
 599                {
 0600                    writer.WriteNode(r, false);
 601                }
 0602            }
 0603        }
 604
 605        protected override XmlDictionaryReader OnGetReaderAtDetailContents()
 606        {
 2607            XmlDictionaryReader reader = _detail.GetReader(0);
 2608            reader.Read(); // Skip the detail element
 2609            return reader;
 610        }
 611
 612        private bool ShouldWriteDetailAttribute(EnvelopeVersion targetVersion, string prefix, string localName, string a
 613        {
 614            // Handle fault detail version conversion from Soap12 to Soap11 -- scope tightly to only conversion from Soa
 615            // SOAP 1.1 specifications allow an arbitrary element within <fault>, hence:
 616            // transform this IFF the SOAP namespace specified will affect the namespace of the <detail> element,
 617            // AND the namespace specified is exactly the Soap12 Namespace.
 0618            bool shouldSkip = _receivedVersion == EnvelopeVersion.Soap12    // original incoming version
 0619                                && targetVersion == EnvelopeVersion.Soap11      // version to serialize to
 0620                                && string.IsNullOrEmpty(prefix)                 // attribute prefix
 0621                                && localName == "xmlns"                         // only transform namespace attributes, 
 0622                                && attributeValue == XD.Message12Dictionary.Namespace.Value;
 623
 0624            return !shouldSkip;
 625        }
 626
 627        public static ReceivedFault CreateFaultNone(XmlDictionaryReader reader, int maxBufferSize)
 628        {
 0629            return CreateFault12Driver(reader, maxBufferSize, EnvelopeVersion.None);
 630        }
 631
 632        private static ReceivedFault CreateFault12Driver(XmlDictionaryReader reader, int maxBufferSize, EnvelopeVersion 
 633        {
 2634            reader.ReadStartElement(XD.MessageDictionary.Fault, version.DictionaryNamespace);
 2635            reader.ReadStartElement(XD.Message12Dictionary.FaultCode, version.DictionaryNamespace);
 2636            FaultCode code = ReadFaultCode12Driver(reader, version);
 2637            reader.ReadEndElement();
 2638            List<FaultReasonText> translations = new List<FaultReasonText>();
 2639            if (reader.IsEmptyElement)
 640            {
 0641                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException(SR.AtLeastOneFaultReasonMu
 642            }
 643            else
 644            {
 2645                reader.ReadStartElement(XD.Message12Dictionary.FaultReason, version.DictionaryNamespace);
 6646                while (reader.IsStartElement(XD.Message12Dictionary.FaultText, version.DictionaryNamespace))
 647                {
 4648                    translations.Add(ReadTranslation12(reader));
 649                }
 650
 2651                reader.ReadEndElement();
 652            }
 653
 2654            string actor = "";
 2655            string node = "";
 2656            if (reader.IsStartElement(XD.Message12Dictionary.FaultNode, version.DictionaryNamespace))
 657            {
 0658                node = reader.ReadElementContentAsString();
 659            }
 660
 2661            if (reader.IsStartElement(XD.Message12Dictionary.FaultRole, version.DictionaryNamespace))
 662            {
 0663                actor = reader.ReadElementContentAsString();
 664            }
 665
 2666            XmlBuffer detail = null;
 2667            if (reader.IsStartElement(XD.Message12Dictionary.FaultDetail, version.DictionaryNamespace))
 668            {
 2669                detail = new XmlBuffer(maxBufferSize);
 2670                XmlDictionaryWriter writer = detail.OpenSection(reader.Quotas);
 2671                writer.WriteNode(reader, false);
 2672                detail.CloseSection();
 2673                detail.Close();
 674            }
 2675            reader.ReadEndElement();
 2676            FaultReason reason = new FaultReason(translations);
 2677            return new ReceivedFault(code, reason, actor, node, detail, version);
 678        }
 679
 680        private static FaultCode ReadFaultCode12Driver(XmlDictionaryReader reader, EnvelopeVersion version)
 681        {
 2682            reader.ReadStartElement(XD.Message12Dictionary.FaultValue, version.DictionaryNamespace);
 2683            XmlUtil.ReadContentAsQName(reader, out string localName, out string ns);
 2684            reader.ReadEndElement();
 2685            if (reader.IsStartElement(XD.Message12Dictionary.FaultSubcode, version.DictionaryNamespace))
 686            {
 0687                reader.ReadStartElement();
 0688                FaultCode subCode = ReadFaultCode12Driver(reader, version);
 0689                reader.ReadEndElement();
 0690                return new FaultCode(localName, ns, subCode);
 691            }
 2692            return new FaultCode(localName, ns);
 693        }
 694
 695        public static ReceivedFault CreateFault12(XmlDictionaryReader reader, int maxBufferSize)
 696        {
 2697            return CreateFault12Driver(reader, maxBufferSize, EnvelopeVersion.Soap12);
 698        }
 699
 700        private static FaultReasonText ReadTranslation12(XmlDictionaryReader reader)
 701        {
 4702            string xmlLang = XmlUtil.GetXmlLangAttribute(reader);
 4703            string text = reader.ReadElementContentAsString();
 4704            return new FaultReasonText(text, xmlLang);
 705        }
 706
 707        public static ReceivedFault CreateFault11(XmlDictionaryReader reader, int maxBufferSize)
 708        {
 0709            reader.ReadStartElement(XD.MessageDictionary.Fault, XD.Message11Dictionary.Namespace);
 0710            reader.ReadStartElement(XD.Message11Dictionary.FaultCode, XD.Message11Dictionary.FaultNamespace);
 0711            XmlUtil.ReadContentAsQName(reader, out string name, out string ns);
 0712            FaultCode code = new FaultCode(name, ns);
 0713            reader.ReadEndElement();
 714
 0715            string xmlLang = reader.XmlLang;
 0716            reader.MoveToContent();  // Don't do IsStartElement.  FaultString is required, so let the reader throw.
 0717            string text = reader.ReadElementContentAsString(XD.Message11Dictionary.FaultString.Value, XD.Message11Dictio
 0718            FaultReasonText translation = new FaultReasonText(text, xmlLang);
 719
 0720            string actor = "";
 0721            if (reader.IsStartElement(XD.Message11Dictionary.FaultActor, XD.Message11Dictionary.FaultNamespace))
 722            {
 0723                actor = reader.ReadElementContentAsString();
 724            }
 725
 0726            XmlBuffer detail = null;
 0727            if (reader.IsStartElement(XD.Message11Dictionary.FaultDetail, XD.Message11Dictionary.FaultNamespace))
 728            {
 0729                detail = new XmlBuffer(maxBufferSize);
 0730                XmlDictionaryWriter writer = detail.OpenSection(reader.Quotas);
 0731                writer.WriteNode(reader, false);
 0732                detail.CloseSection();
 0733                detail.Close();
 734            }
 0735            reader.ReadEndElement();
 0736            FaultReason reason = new FaultReason(translation);
 0737            return new ReceivedFault(code, reason, actor, actor, detail, EnvelopeVersion.Soap11);
 738        }
 739    }
 740}