< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Description.XmlSerializerOperationBehavior
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Description/XmlSerializerOperationBehavior.cs
Line coverage
62%
Covered lines: 243
Uncovered lines: 146
Coverable lines: 389
Total lines: 1225
Line coverage: 62.4%
Branch coverage
52%
Covered branches: 122
Total branches: 232
Branch coverage: 52.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%110%
.ctor(...)0%440%
.ctor(...)0%220%
.ctor(...)100%11100%
CreateOperationFormatter(...)100%110%
CreateOperationFormatter(...)100%110%
AddBehaviors(...)100%110%
AddBuiltInBehaviors(...)100%11100%
AddBehaviors(...)100%66100%
CreateFormatter()100%11100%
CreateFaultFormatter(...)100%11100%
CoreWCF.Description.IOperationBehavior.Validate(...)100%11100%
CoreWCF.Description.IOperationBehavior.AddBindingParameters(...)100%11100%
CoreWCF.Description.IOperationBehavior.ApplyDispatchBehavior(...)66.66%121271.42%
CoreWCF.Description.IOperationBehavior.ApplyClientBehavior(...)0%10100%
CoreWCF.Description.IWsdlExportExtension.ExportEndpoint(...)50%4466.66%
CoreWCF.Description.IWsdlExportExtension.ExportContract(...)50%4466.66%
GetXmlMappings()0%16160%
.ctor(...)100%11100%
EnsureMessageInfos()100%22100%
FindAttribute(...)50%44100%
ReflectOperation(...)50%2275%
ReflectOperation(...)100%11100%
.ctor(...)58.33%121278.26%
SetUnknownHeaderInDescription(...)64.28%141472.22%
EnsureMessageInfos()88.46%262681.25%
GenerateXmlSerializerFaultContractInfos()50%2244.44%
CreateMessageInfo(...)75%4490%
CreateHeaderDescriptionTable(...)50%161660.86%
LoadBodyMapping(...)77.77%181872%
GetWrapperPart(...)0%10100%
GetWrappedParts(...)0%10100%
LoadHeadersMapping(...)66.66%121268.42%
ImportMembersMapping(...)100%22100%
ImportFaultElement(...)0%440%
.ctor(...)100%11100%
ImportMembersMapping(...)75%4488.88%
ImportTypeMapping(...)0%220%
IncludeType(...)100%22100%
.ctor(...)100%11100%
AddSerializer(...)100%22100%
GetSerializer(...)100%66100%
GenerateSerializers()62.5%8875%
CreateSerializersFromMappings(...)100%11100%
.ctor(...)100%11100%
GetSerializer()100%11100%
.ctor(...)0%440%
SetBody(...)100%11100%
SetHeaders(...)100%11100%
SetHeaderDescriptionTable(...)100%11100%
SetUnknownHeaderDescription(...)100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Description/XmlSerializerOperationBehavior.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;
 6using System.Collections.Generic;
 7using System.Collections.ObjectModel;
 8using System.Linq;
 9using System.Reflection;
 10using System.Xml;
 11using System.Xml.Serialization;
 12using CoreWCF.Channels;
 13using CoreWCF.Collections.Generic;
 14using CoreWCF.Dispatcher;
 15using CoreWCF.Runtime;
 16
 17namespace CoreWCF.Description
 18{
 19    public class XmlSerializerOperationBehavior : IOperationBehavior, IWsdlExportExtension
 20    {
 21        public XmlSerializerOperationBehavior(OperationDescription operation)
 022            : this(operation, null)
 23        {
 024        }
 25
 026        public XmlSerializerOperationBehavior(OperationDescription operation, XmlSerializerFormatAttribute attribute)
 27        {
 028            if (operation == null)
 29            {
 030                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(operation));
 31            }
 32
 033            Reflector parentReflector = new Reflector(operation.DeclaringContract.Namespace, operation.DeclaringContract
 034            OperationReflector = parentReflector.ReflectOperation(operation, attribute ?? new XmlSerializerFormatAttribu
 035        }
 36
 37        public XmlSerializerOperationBehavior(OperationDescription operation, XmlSerializerFormatAttribute attribute, st
 038            : this(operation, attribute)
 39        {
 040            OperationReflector = new Reflector(contractType, null).ReflectOperation(operation, attribute ?? new XmlSeria
 041        }
 42
 5243        private XmlSerializerOperationBehavior(Reflector.OperationReflector reflector, bool builtInOperationBehavior)
 44        {
 45            Fx.Assert(reflector != null, "");
 5246            OperationReflector = reflector;
 5247            IsBuiltInOperationBehavior = builtInOperationBehavior;
 5248        }
 49
 41150        internal Reflector.OperationReflector OperationReflector { get; }
 51
 052        internal bool IsBuiltInOperationBehavior { get; }
 53
 54        public XmlSerializerFormatAttribute XmlSerializerFormatAttribute
 55        {
 56            get
 57            {
 3858                return OperationReflector.Attribute;
 59            }
 60        }
 61
 62        internal static XmlSerializerOperationFormatter CreateOperationFormatter(OperationDescription operation)
 63        {
 064            return new XmlSerializerOperationBehavior(operation).CreateFormatter();
 65        }
 66
 67        internal static XmlSerializerOperationFormatter CreateOperationFormatter(OperationDescription operation, XmlSeri
 68        {
 069            return new XmlSerializerOperationBehavior(operation, attr).CreateFormatter();
 70        }
 71
 72        internal static void AddBehaviors(ContractDescription contract)
 73        {
 074            AddBehaviors(contract, false);
 075        }
 76
 77        internal static void AddBuiltInBehaviors(ContractDescription contract)
 78        {
 3279            AddBehaviors(contract, true);
 3280        }
 81
 82        private static void AddBehaviors(ContractDescription contract, bool builtInOperationBehavior)
 83        {
 3284            Reflector reflector = new Reflector(contract.Namespace, contract.ContractType);
 85
 18486            foreach (OperationDescription operation in contract.Operations)
 87            {
 6088                Reflector.OperationReflector operationReflector = reflector.ReflectOperation(operation);
 6089                if (operationReflector != null)
 90                {
 6091                    bool isInherited = operation.DeclaringContract != contract;
 6092                    if (!isInherited)
 93                    {
 5294                        operation.Behaviors.Add(new XmlSerializerOperationBehavior(operationReflector, builtInOperationB
 95                        //operation.Behaviors.Add(new XmlSerializerOperationGenerator(new XmlSerializerImportOptions()))
 96                    }
 97                }
 98            }
 3299        }
 100
 101        internal XmlSerializerOperationFormatter CreateFormatter()
 102        {
 50103            return new XmlSerializerOperationFormatter(OperationReflector.Operation, OperationReflector.Attribute, Opera
 104        }
 105
 106        private XmlSerializerFaultFormatter CreateFaultFormatter(SynchronizedCollection<FaultContractInfo> faultContract
 107        {
 5108            return new XmlSerializerFaultFormatter(faultContractInfos, OperationReflector.XmlSerializerFaultContractInfo
 109        }
 110
 111        void IOperationBehavior.Validate(OperationDescription description)
 112        {
 50113        }
 114
 115        void IOperationBehavior.AddBindingParameters(OperationDescription description, BindingParameterCollection parame
 116        {
 59117        }
 118
 119        void IOperationBehavior.ApplyDispatchBehavior(OperationDescription description, DispatchOperation dispatch)
 120        {
 50121            if (description == null)
 122            {
 0123                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(description));
 124            }
 125
 50126            if (dispatch == null)
 127            {
 0128                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(dispatch));
 129            }
 130
 50131            if (dispatch.Formatter == null)
 132            {
 50133                dispatch.Formatter = (IDispatchMessageFormatter)CreateFormatter();
 50134                dispatch.DeserializeRequest = OperationReflector.RequestRequiresSerialization;
 50135                dispatch.SerializeReply = OperationReflector.ReplyRequiresSerialization;
 136            }
 137
 50138            if (OperationReflector.Attribute.SupportFaults)
 139            {
 5140                if (!dispatch.IsFaultFormatterSetExplicit)
 141                {
 5142                    dispatch.FaultFormatter = (IDispatchFaultFormatter)CreateFaultFormatter(dispatch.FaultContractInfos)
 143                }
 144                else
 145                {
 0146                    if (dispatch.FaultFormatter is IDispatchFaultFormatterWrapper wrapper)
 147                    {
 0148                        wrapper.InnerFaultFormatter = (IDispatchFaultFormatter)CreateFaultFormatter(dispatch.FaultContra
 149                    }
 150                }
 151            }
 45152        }
 153
 154        void IOperationBehavior.ApplyClientBehavior(OperationDescription description, ClientOperation proxy)
 155        {
 0156            if (description == null)
 157            {
 0158                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(description));
 159            }
 160
 0161            if (proxy == null)
 162            {
 0163                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(proxy));
 164            }
 165
 0166            if (proxy.Formatter == null)
 167            {
 0168                proxy.Formatter = (IClientMessageFormatter)CreateFormatter();
 0169                proxy.SerializeRequest = OperationReflector.RequestRequiresSerialization;
 0170                proxy.DeserializeReply = OperationReflector.ReplyRequiresSerialization;
 171            }
 172
 0173            if (OperationReflector.Attribute.SupportFaults && !proxy.IsFaultFormatterSetExplicit)
 174            {
 0175                proxy.FaultFormatter = (IClientFaultFormatter)CreateFaultFormatter(proxy.FaultContractInfos);
 176            }
 0177        }
 178
 179        void IWsdlExportExtension.ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext endpointContext)
 180        {
 9181            if (exporter == null)
 0182                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(exporter));
 9183            if (endpointContext == null)
 0184                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(endpointContext));
 185
 9186            MessageContractExporter.ExportMessageBinding(exporter, endpointContext, typeof(XmlSerializerMessageContractE
 9187        }
 188
 189        void IWsdlExportExtension.ExportContract(WsdlExporter exporter, WsdlContractConversionContext contractContext)
 190        {
 9191            if (exporter == null)
 0192                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(exporter));
 9193            if (contractContext == null)
 0194                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(contractContext));
 195
 9196            new XmlSerializerMessageContractExporter(exporter, contractContext, OperationReflector.Operation, this).Expo
 9197        }
 198
 199        public Collection<XmlMapping> GetXmlMappings()
 200        {
 0201            Collection<XmlMapping> mappings = new Collection<XmlMapping>();
 0202            if (OperationReflector.Request != null && OperationReflector.Request.HeadersMapping != null)
 203            {
 0204                mappings.Add(OperationReflector.Request.HeadersMapping);
 205            }
 206
 0207            if (OperationReflector.Request != null && OperationReflector.Request.BodyMapping != null)
 208            {
 0209                mappings.Add(OperationReflector.Request.BodyMapping);
 210            }
 211
 0212            if (OperationReflector.Reply != null && OperationReflector.Reply.HeadersMapping != null)
 213            {
 0214                mappings.Add(OperationReflector.Reply.HeadersMapping);
 215            }
 216
 0217            if (OperationReflector.Reply != null && OperationReflector.Reply.BodyMapping != null)
 218            {
 0219                mappings.Add(OperationReflector.Reply.BodyMapping);
 220            }
 221
 0222            return mappings;
 223        }
 224
 225        // helper for reflecting operations
 226        internal class Reflector
 227        {
 228            private readonly XmlSerializerImporter _importer;
 229            private readonly SerializerGenerationContext _generation;
 34230            private readonly Collection<OperationReflector> _operationReflectors = new Collection<OperationReflector>();
 34231            private readonly object _thisLock = new object();
 232
 34233            internal Reflector(string defaultNs, Type type)
 234            {
 34235                _importer = new XmlSerializerImporter(defaultNs);
 34236                _generation = new SerializerGenerationContext(type);
 34237            }
 238
 239            internal void EnsureMessageInfos()
 240            {
 123241                lock (_thisLock)
 242                {
 940243                    foreach (OperationReflector operationReflector in _operationReflectors)
 244                    {
 347245                        operationReflector.EnsureMessageInfos();
 246                    }
 247                }
 123248            }
 249
 250            private static XmlSerializerFormatAttribute FindAttribute(OperationDescription operation)
 251            {
 69252                Type contractType = operation.DeclaringContract?.ContractType;
 69253                XmlSerializerFormatAttribute contractFormatAttribute = contractType != null ? TypeLoader.GetFormattingAt
 69254                return TypeLoader.GetFormattingAttribute(operation.OperationMethod, contractFormatAttribute) as XmlSeria
 255            }
 256
 257            // auto-reflects the operation, returning null if no attribute was found or inherited
 258            internal OperationReflector ReflectOperation(OperationDescription operation)
 259            {
 69260                XmlSerializerFormatAttribute attr = FindAttribute(operation);
 69261                if (attr == null)
 262                {
 0263                    return null;
 264                }
 265
 69266                return ReflectOperation(operation, attr);
 267            }
 268
 269            // overrides the auto-reflection with an attribute
 270            internal OperationReflector ReflectOperation(OperationDescription operation, XmlSerializerFormatAttribute at
 271            {
 69272                OperationReflector operationReflector = new OperationReflector(this, operation, attrOverride, true/*refl
 69273                _operationReflectors.Add(operationReflector);
 274
 69275                return operationReflector;
 276            }
 277
 278            internal class OperationReflector
 279            {
 280                private readonly Reflector _parent;
 281
 282                internal readonly OperationDescription Operation;
 283                internal readonly XmlSerializerFormatAttribute Attribute;
 284
 285                internal readonly bool IsEncoded;
 286                internal readonly bool IsRpc;
 287                internal readonly bool IsOneWay;
 288                internal readonly bool RequestRequiresSerialization;
 289                internal readonly bool ReplyRequiresSerialization;
 290                private readonly string _keyBase;
 291                private MessageInfo _request;
 292                private MessageInfo _reply;
 293                private SynchronizedCollection<XmlSerializerFaultContractInfo> _xmlSerializerFaultContractInfos;
 294
 69295                internal OperationReflector(Reflector parent, OperationDescription operation, XmlSerializerFormatAttribu
 296                {
 297                    Fx.Assert(parent != null, "");
 298                    Fx.Assert(operation != null, "");
 299                    Fx.Assert(attr != null, "");
 300
 69301                    OperationFormatter.Validate(operation, attr.Style == OperationFormatStyle.Rpc, attr.IsEncoded);
 302
 69303                    _parent = parent;
 304
 69305                    Operation = operation;
 69306                    Attribute = attr;
 307
 69308                    IsEncoded = attr.IsEncoded;
 69309                    IsRpc = (attr.Style == OperationFormatStyle.Rpc);
 69310                    IsOneWay = operation.Messages.Count == 1;
 311
 69312                    RequestRequiresSerialization = !operation.Messages[0].IsUntypedMessage;
 69313                    ReplyRequiresSerialization = !IsOneWay && !operation.Messages[1].IsUntypedMessage;
 314
 69315                    MethodInfo methodInfo = operation.OperationMethod;
 69316                    if (methodInfo == null)
 317                    {
 318                        // keyBase needs to be unique within the scope of the parent reflector
 0319                        _keyBase = string.Empty;
 0320                        if (operation.DeclaringContract != null)
 321                        {
 0322                            _keyBase = operation.DeclaringContract.Name + "," + operation.DeclaringContract.Namespace + 
 323                        }
 0324                        _keyBase = _keyBase + operation.Name;
 325                    }
 326                    else
 327                    {
 69328                        _keyBase = methodInfo.DeclaringType.FullName + ":" + methodInfo.ToString();
 329                    }
 330
 414331                    foreach (MessageDescription message in operation.Messages)
 332                    {
 284333                        foreach (MessageHeaderDescription header in message.Headers)
 334                        {
 4335                            SetUnknownHeaderInDescription(header);
 336                        }
 337                    }
 338
 69339                    if (!reflectOnDemand)
 340                    {
 0341                        EnsureMessageInfos();
 342                    }
 69343                }
 344
 345                private void SetUnknownHeaderInDescription(MessageHeaderDescription header)
 346                {
 4347                    if (IsEncoded) //XmlAnyElementAttribute does not apply
 348                    {
 0349                        return;
 350                    }
 351
 4352                    if (header.AdditionalAttributesProvider != null)
 353                    {
 4354                        object[] attributes = header
 4355                            .AdditionalAttributesProvider
 4356                            .GetCustomAttributes(false)
 4357                            .ToArray();
 358
 4359                        bool isUnknown = false;
 4360                        bool xmlIgnore = false;
 361
 16362                        foreach (object attribute in attributes)
 363                        {
 4364                            if (attribute is XmlAnyElementAttribute elementAttribute)
 365                            {
 0366                                if (string.IsNullOrEmpty(elementAttribute.Name))
 367                                {
 0368                                    isUnknown = true;
 369                                }
 370                            }
 371
 372                            // In the original full framework code using XmlAttributes, the XmlAnyElements collection is
 373                            // if the XmlIgnore attribute is present.
 4374                            if (attribute is XmlIgnoreAttribute)
 375                            {
 0376                                xmlIgnore = true;
 0377                                break; // XmlIgnore overrides all so no need to continue if found.
 378                            }
 379                        }
 380
 4381                        header.IsUnknownHeaderCollection = isUnknown && !xmlIgnore;
 382                    }
 4383                }
 384
 385                private string ContractName
 386                {
 2387                    get { return Operation.DeclaringContract.Name; }
 388                }
 389
 390                private string ContractNamespace
 391                {
 2392                    get { return Operation.DeclaringContract.Namespace; }
 393                }
 394
 395                internal MessageInfo Request
 396                {
 397                    get
 398                    {
 59399                        _parent.EnsureMessageInfos();
 59400                        return _request;
 401                    }
 402                }
 403
 404                internal MessageInfo Reply
 405                {
 406                    get
 407                    {
 59408                        _parent.EnsureMessageInfos();
 59409                        return _reply;
 410                    }
 411                }
 412
 413                internal SynchronizedCollection<XmlSerializerFaultContractInfo> XmlSerializerFaultContractInfos
 414                {
 415                    get
 416                    {
 5417                        _parent.EnsureMessageInfos();
 5418                        return _xmlSerializerFaultContractInfos;
 419                    }
 420                }
 421
 422                internal void EnsureMessageInfos()
 423                {
 347424                    if (_request == null)
 425                    {
 166426                        foreach (Type knownType in Operation.KnownTypes)
 427                        {
 18428                            if (knownType == null)
 429                            {
 0430                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
 431                            }
 432
 18433                            _parent._importer.IncludeType(knownType, IsEncoded);
 434                        }
 65435                        _request = CreateMessageInfo(Operation.Messages[0], ":Request");
 65436                        if (_request != null && IsRpc && Operation.IsValidateRpcWrapperName && _request.BodyMapping.XsdE
 437                        {
 0438                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.F
 439                        }
 440
 65441                        if (!IsOneWay)
 442                        {
 65443                            _reply = CreateMessageInfo(Operation.Messages[1], ":Response");
 65444                            XmlName responseName = TypeLoader.GetBodyWrapperResponseName(Operation.Name);
 65445                            if (_reply != null && IsRpc && Operation.IsValidateRpcWrapperName && _reply.BodyMapping.XsdE
 446                            {
 0447                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
 448                            }
 449                        }
 65450                        if (Attribute.SupportFaults)
 451                        {
 10452                            GenerateXmlSerializerFaultContractInfos();
 453                        }
 454                    }
 347455                }
 456
 457                private void GenerateXmlSerializerFaultContractInfos()
 458                {
 10459                    SynchronizedCollection<XmlSerializerFaultContractInfo> faultInfos = new SynchronizedCollection<XmlSe
 20460                    for (int i = 0; i < Operation.Faults.Count; i++)
 461                    {
 0462                        FaultDescription fault = Operation.Faults[i];
 0463                        FaultContractInfo faultContractInfo = new FaultContractInfo(fault.Action, fault.DetailType, faul
 464
 0465                        XmlMembersMapping xmlMembersMapping = ImportFaultElement(fault, out XmlQualifiedName elementName
 466
 0467                        SerializerStub serializerStub = _parent._generation.AddSerializer(xmlMembersMapping);
 0468                        faultInfos.Add(new XmlSerializerFaultContractInfo(faultContractInfo, serializerStub, elementName
 469                    }
 10470                    _xmlSerializerFaultContractInfos = faultInfos;
 10471                }
 472
 473                private MessageInfo CreateMessageInfo(MessageDescription message, string key)
 474                {
 130475                    if (message.IsUntypedMessage)
 476                    {
 0477                        return null;
 478                    }
 479
 130480                    MessageInfo info = new MessageInfo();
 130481                    if (message.IsTypedMessage)
 482                    {
 12483                        key = message.MessageType.FullName + ":" + IsEncoded + ":" + IsRpc;
 484                    }
 485
 130486                    XmlMembersMapping headersMapping = LoadHeadersMapping(message, key + ":Headers");
 130487                    info.SetHeaders(_parent._generation.AddSerializer(headersMapping));
 130488                    info.SetBody(_parent._generation.AddSerializer(LoadBodyMapping(message, key, out MessagePartDescript
 130489                    CreateHeaderDescriptionTable(message, info, headersMapping);
 130490                    return info;
 491                }
 492
 493                private void CreateHeaderDescriptionTable(MessageDescription message, MessageInfo info, XmlMembersMappin
 494                {
 130495                    int headerNameIndex = 0;
 130496                    OperationFormatter.MessageHeaderDescriptionTable headerDescriptionTable = new OperationFormatter.Mes
 130497                    info.SetHeaderDescriptionTable(headerDescriptionTable);
 268498                    foreach (MessageHeaderDescription header in message.Headers)
 499                    {
 4500                        if (header.IsUnknownHeaderCollection)
 501                        {
 0502                            info.SetUnknownHeaderDescription(header);
 503                        }
 4504                        else if (headersMapping != null)
 505                        {
 4506                            XmlMemberMapping memberMapping = headersMapping[headerNameIndex++];
 507                            string headerName, headerNs;
 4508                            if (IsEncoded)
 509                            {
 0510                                headerName = memberMapping.TypeName;
 0511                                headerNs = memberMapping.TypeNamespace;
 512                            }
 513                            else
 514                            {
 4515                                headerName = memberMapping.XsdElementName;
 4516                                headerNs = memberMapping.Namespace;
 517                            }
 4518                            if (headerName != header.Name)
 519                            {
 0520                                if (message.MessageType != null)
 521                                {
 0522                                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationExcept
 523                                }
 524                                else
 525                                {
 0526                                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationExcept
 527                                }
 528                            }
 4529                            if (headerNs != header.Namespace)
 530                            {
 0531                                if (message.MessageType != null)
 532                                {
 0533                                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationExcept
 534                                }
 535                                else
 536                                {
 0537                                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationExcept
 538                                }
 539                            }
 540
 4541                            headerDescriptionTable.Add(headerName, headerNs, header);
 542                        }
 543                    }
 130544                }
 545
 546                private XmlMembersMapping LoadBodyMapping(MessageDescription message, string mappingKey, out MessagePart
 547                {
 548                    MessagePartDescription returnPart;
 549                    string wrapperName, wrapperNs;
 550                    MessagePartDescriptionCollection bodyParts;
 130551                    if (IsEncoded && message.IsTypedMessage && message.Body.WrapperName == null)
 552                    {
 0553                        MessagePartDescription wrapperPart = GetWrapperPart(message);
 0554                        returnPart = null;
 0555                        rpcEncodedTypedMessageBodyParts = bodyParts = GetWrappedParts(wrapperPart);
 0556                        wrapperName = wrapperPart.Name;
 0557                        wrapperNs = wrapperPart.Namespace;
 558                    }
 559                    else
 560                    {
 130561                        rpcEncodedTypedMessageBodyParts = null;
 130562                        returnPart = OperationFormatter.IsValidReturnValue(message.Body.ReturnValue) ? message.Body.Retu
 130563                        bodyParts = message.Body.Parts;
 130564                        wrapperName = message.Body.WrapperName;
 130565                        wrapperNs = message.Body.WrapperNamespace;
 566                    }
 130567                    bool isWrapped = (wrapperName != null);
 130568                    bool hasReturnValue = returnPart != null;
 130569                    int paramCount = bodyParts.Count + (hasReturnValue ? 1 : 0);
 130570                    if (paramCount == 0 && !isWrapped) // no need to create serializer
 571                    {
 0572                        return null;
 573                    }
 574
 130575                    XmlReflectionMember[] members = new XmlReflectionMember[paramCount];
 130576                    int paramIndex = 0;
 130577                    if (hasReturnValue)
 578                    {
 59579                        members[paramIndex++] = XmlSerializerHelper.GetXmlReflectionMember(returnPart, IsRpc, IsEncoded,
 580                    }
 581
 422582                    for (int i = 0; i < bodyParts.Count; i++)
 583                    {
 81584                        members[paramIndex++] = XmlSerializerHelper.GetXmlReflectionMember(bodyParts[i], IsRpc, IsEncode
 585                    }
 586
 130587                    if (!isWrapped)
 588                    {
 0589                        wrapperNs = ContractNamespace;
 590                    }
 591
 130592                    return ImportMembersMapping(wrapperName, wrapperNs, members, isWrapped, IsRpc, mappingKey);
 593                }
 594
 595                private MessagePartDescription GetWrapperPart(MessageDescription message)
 596                {
 0597                    if (message.Body.Parts.Count != 1)
 598                    {
 0599                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma
 600                    }
 601
 0602                    MessagePartDescription bodyPart = message.Body.Parts[0];
 0603                    Type bodyObjectType = bodyPart.Type;
 0604                    if (bodyObjectType.GetTypeInfo().BaseType != null && bodyObjectType.GetTypeInfo().BaseType != typeof
 605                    {
 0606                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma
 607                    }
 608
 0609                    if (typeof(IEnumerable).IsAssignableFrom(bodyObjectType))
 610                    {
 0611                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma
 612                    }
 613
 0614                    if (typeof(IXmlSerializable).IsAssignableFrom(bodyObjectType))
 615                    {
 0616                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma
 617                    }
 618
 0619                    return bodyPart;
 620                }
 621
 622                private MessagePartDescriptionCollection GetWrappedParts(MessagePartDescription bodyPart)
 623                {
 0624                    Type bodyObjectType = bodyPart.Type;
 0625                    MessagePartDescriptionCollection partList = new MessagePartDescriptionCollection();
 0626                    foreach (MemberInfo member in bodyObjectType.GetMembers(BindingFlags.Instance | BindingFlags.Public)
 627                    {
 0628                        if ((member as PropertyInfo) == null && (member as FieldInfo) == null)
 629                        {
 630                            continue;
 631                        }
 632
 0633                        if (member.IsDefined(typeof(SoapIgnoreAttribute), inherit: false))
 634                        {
 635                            continue;
 636                        }
 637
 0638                        XmlName xmlName = new XmlName(member.Name);
 0639                        MessagePartDescription part = new MessagePartDescription(xmlName.EncodedName, string.Empty);
 0640                        part.AdditionalAttributesProvider = part.MemberInfo = member;
 0641                        part.Index = part.SerializationPosition = partList.Count;
 0642                        part.Type = (member is PropertyInfo) ? ((PropertyInfo)member).PropertyType : ((FieldInfo)member)
 0643                        partList.Add(part);
 644                    }
 0645                    return partList;
 646                }
 647
 648                private XmlMembersMapping LoadHeadersMapping(MessageDescription message, string mappingKey)
 649                {
 130650                    int headerCount = message.Headers.Count;
 651
 130652                    if (headerCount == 0)
 653                    {
 128654                        return null;
 655                    }
 656
 2657                    if (IsEncoded)
 658                    {
 0659                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma
 660                    }
 661
 4662                    int unknownHeaderCount = 0, headerIndex = 0;
 2663                    XmlReflectionMember[] members = new XmlReflectionMember[headerCount];
 12664                    for (int i = 0; i < headerCount; i++)
 665                    {
 4666                        MessageHeaderDescription header = message.Headers[i];
 4667                        if (!header.IsUnknownHeaderCollection)
 668                        {
 4669                            members[headerIndex++] = XmlSerializerHelper.GetXmlReflectionMember(header, false/*isRpc*/, 
 670                        }
 671                        else
 672                        {
 0673                            unknownHeaderCount++;
 674                        }
 675                    }
 676
 2677                    if (unknownHeaderCount == headerCount)
 678                    {
 0679                        return null;
 680                    }
 681
 2682                    if (unknownHeaderCount > 0)
 683                    {
 0684                        XmlReflectionMember[] newMembers = new XmlReflectionMember[headerCount - unknownHeaderCount];
 0685                        Array.Copy(members, newMembers, newMembers.Length);
 0686                        members = newMembers;
 687                    }
 688
 2689                    return ImportMembersMapping(ContractName, ContractNamespace, members, false /*isWrapped*/, false /*i
 690                }
 691
 692                internal XmlMembersMapping ImportMembersMapping(string elementName, string ns, XmlReflectionMember[] mem
 693                {
 132694                    string key = mappingKey.StartsWith(":", StringComparison.Ordinal) ? _keyBase + mappingKey : mappingK
 132695                    return _parent._importer.ImportMembersMapping(new XmlName(elementName, true /*isEncoded*/), ns, memb
 696                }
 697
 698                internal XmlMembersMapping ImportFaultElement(FaultDescription fault, out XmlQualifiedName elementName)
 699                {
 700                    // the number of reflection members is always 1 because there is only one fault detail type
 0701                    XmlReflectionMember[] members = new XmlReflectionMember[1];
 702
 0703                    XmlName faultElementName = fault.ElementName;
 0704                    string faultNamespace = fault.Namespace;
 0705                    if (faultElementName == null)
 706                    {
 0707                        XmlTypeMapping mapping = _parent._importer.ImportTypeMapping(fault.DetailType, IsEncoded);
 0708                        faultElementName = new XmlName(mapping.ElementName, IsEncoded);
 0709                        faultNamespace = mapping.Namespace;
 0710                        if (faultElementName == null)
 711                        {
 0712                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.F
 713                        }
 714                    }
 715
 0716                    elementName = new XmlQualifiedName(faultElementName.DecodedName, faultNamespace);
 717
 0718                    members[0] = XmlSerializerHelper.GetXmlReflectionMember(null /*memberName*/, faultElementName, fault
 0719                        null /*additionalAttributesProvider*/, false /*isMultiple*/, IsEncoded, false /*isWrapped*/);
 720
 0721                    string mappingKey = "fault:" + faultElementName.DecodedName + ":" + faultNamespace;
 0722                    return ImportMembersMapping(faultElementName.EncodedName, faultNamespace, members, false /*hasWrappe
 723                }
 724            }
 725
 726            private class XmlSerializerImporter
 727            {
 728                private readonly string _defaultNs;
 729                private XmlReflectionImporter _xmlImporter;
 730                private SoapReflectionImporter _soapImporter;
 731                private Dictionary<string, XmlMembersMapping> _xmlMappings;
 732
 34733                internal XmlSerializerImporter(string defaultNs)
 734                {
 34735                    _defaultNs = defaultNs;
 34736                    _xmlImporter = null;
 34737                    _soapImporter = null;
 34738                }
 739
 740                private SoapReflectionImporter SoapImporter
 741                {
 742                    get
 743                    {
 42744                        if (_soapImporter == null)
 745                        {
 6746                            _soapImporter = new SoapReflectionImporter(NamingHelper.CombineUriStrings(_defaultNs, "encod
 747                        }
 42748                        return _soapImporter;
 749                    }
 750                }
 751
 752                private XmlReflectionImporter XmlImporter
 753                {
 754                    get
 755                    {
 108756                        if (_xmlImporter == null)
 757                        {
 30758                            _xmlImporter = new XmlReflectionImporter(_defaultNs);
 759                        }
 108760                        return _xmlImporter;
 761                    }
 762                }
 763
 764                private Dictionary<string, XmlMembersMapping> XmlMappings
 765                {
 766                    get
 767                    {
 264768                        if (_xmlMappings == null)
 769                        {
 32770                            _xmlMappings = new Dictionary<string, XmlMembersMapping>();
 771                        }
 264772                        return _xmlMappings;
 773                    }
 774                }
 775
 776                internal XmlMembersMapping ImportMembersMapping(XmlName elementName, string ns, XmlReflectionMember[] me
 777                {
 132778                    string mappingName = elementName.DecodedName;
 132779                    if (XmlMappings.TryGetValue(mappingKey, out XmlMembersMapping mapping))
 780                    {
 0781                        return mapping;
 782                    }
 783
 132784                    if (isEncoded)
 785                    {
 32786                        mapping = SoapImporter.ImportMembersMapping(mappingName, ns, members, hasWrapperElement, rpc);
 787                    }
 788                    else
 789                    {
 100790                        mapping = XmlImporter.ImportMembersMapping(mappingName, ns, members, hasWrapperElement, rpc);
 791                    }
 792
 132793                    mapping.SetKey(mappingKey);
 132794                    XmlMappings.Add(mappingKey, mapping);
 132795                    return mapping;
 796                }
 797
 798                internal XmlTypeMapping ImportTypeMapping(Type type, bool isEncoded)
 799                {
 0800                    if (isEncoded)
 801                    {
 0802                        return SoapImporter.ImportTypeMapping(type);
 803                    }
 804                    else
 805                    {
 0806                        return XmlImporter.ImportTypeMapping(type);
 807                    }
 808                }
 809
 810                internal void IncludeType(Type knownType, bool isEncoded)
 811                {
 18812                    if (isEncoded)
 813                    {
 10814                        SoapImporter.IncludeType(knownType);
 815                    }
 816                    else
 817                    {
 8818                        XmlImporter.IncludeType(knownType);
 819                    }
 8820                }
 821            }
 822
 823            internal class SerializerGenerationContext
 824            {
 34825                private readonly List<XmlMembersMapping> _mappings = new List<XmlMembersMapping>();
 826                private XmlSerializer[] _serializers = null;
 827                private readonly Type _type;
 34828                private readonly object _thisLock = new object();
 829
 34830                internal SerializerGenerationContext(Type type)
 831                {
 34832                    _type = type;
 34833                }
 834
 835                // returns a stub to a serializer
 836                internal SerializerStub AddSerializer(XmlMembersMapping mapping)
 837                {
 260838                    int handle = -1;
 260839                    if (mapping != null)
 840                    {
 132841                        handle = ((IList)_mappings).Add(mapping);
 842                    }
 843
 260844                    return new SerializerStub(this, mapping, handle);
 845                }
 846
 847                internal XmlSerializer GetSerializer(int handle)
 848                {
 82849                    if (handle < 0)
 850                    {
 40851                        return null;
 852                    }
 853
 42854                    if (_serializers == null)
 855                    {
 20856                        lock (_thisLock)
 857                        {
 20858                            if (_serializers == null)
 859                            {
 20860                                _serializers = GenerateSerializers();
 861                            }
 20862                        }
 863                    }
 42864                    return _serializers[handle];
 865                }
 866
 867                private XmlSerializer[] GenerateSerializers()
 868                {
 869                    //this.Mappings may have duplicate mappings (for e.g. same message contract is used by more than one
 870                    //XmlSerializer.FromMappings require unique mappings. The following code uniquifies, calls FromMappi
 20871                    List<XmlMembersMapping> uniqueMappings = new List<XmlMembersMapping>();
 20872                    int[] uniqueIndexes = new int[_mappings.Count];
 176873                    for (int srcIndex = 0; srcIndex < _mappings.Count; srcIndex++)
 874                    {
 68875                        XmlMembersMapping mapping = _mappings[srcIndex];
 68876                        int uniqueIndex = uniqueMappings.IndexOf(mapping);
 68877                        if (uniqueIndex < 0)
 878                        {
 68879                            uniqueMappings.Add(mapping);
 68880                            uniqueIndex = uniqueMappings.Count - 1;
 881                        }
 68882                        uniqueIndexes[srcIndex] = uniqueIndex;
 883                    }
 20884                    XmlSerializer[] uniqueSerializers = CreateSerializersFromMappings(uniqueMappings.ToArray(), _type);
 20885                    if (uniqueMappings.Count == _mappings.Count)
 886                    {
 20887                        return uniqueSerializers;
 888                    }
 889
 0890                    XmlSerializer[] serializers = new XmlSerializer[_mappings.Count];
 0891                    for (int i = 0; i < _mappings.Count; i++)
 892                    {
 0893                        serializers[i] = uniqueSerializers[uniqueIndexes[i]];
 894                    }
 0895                    return serializers;
 896                }
 897
 898                private XmlSerializer[] CreateSerializersFromMappings(XmlMapping[] mappings, Type type)
 899                {
 20900                    return XmlSerializer.FromMappings(mappings, type);
 901                }
 902            }
 903
 904            internal struct SerializerStub
 905            {
 906                private readonly SerializerGenerationContext _context;
 907
 908                internal readonly XmlMembersMapping Mapping;
 909                internal readonly int Handle;
 910
 911                internal SerializerStub(SerializerGenerationContext context, XmlMembersMapping mapping, int handle)
 912                {
 260913                    _context = context;
 260914                    Mapping = mapping;
 260915                    Handle = handle;
 260916                }
 917
 918                internal XmlSerializer GetSerializer()
 919                {
 82920                    return _context.GetSerializer(Handle);
 921                }
 922            }
 923
 924            internal class XmlSerializerFaultContractInfo
 925            {
 926                private readonly SerializerStub _serializerStub;
 927                private XmlSerializerObjectSerializer _serializer;
 928
 0929                internal XmlSerializerFaultContractInfo(FaultContractInfo faultContractInfo, SerializerStub serializerSt
 0930                    XmlQualifiedName faultContractElementName)
 931                {
 0932                    FaultContractInfo = faultContractInfo ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumen
 0933                    _serializerStub = serializerStub;
 0934                    FaultContractElementName = faultContractElementName ?? throw DiagnosticUtility.ExceptionUtility.Thro
 0935                }
 936
 0937                internal FaultContractInfo FaultContractInfo { get; }
 938
 0939                internal XmlQualifiedName FaultContractElementName { get; }
 940
 941                internal XmlSerializerObjectSerializer Serializer
 942                {
 943                    get
 944                    {
 0945                        if (_serializer == null)
 946                        {
 0947                            _serializer = new XmlSerializerObjectSerializer(FaultContractInfo.Detail, FaultContractEleme
 948                        }
 949
 0950                        return _serializer;
 951                    }
 952                }
 953            }
 954
 955            internal class MessageInfo : XmlSerializerOperationFormatter.MessageInfo
 956            {
 957                private SerializerStub _headers;
 958                private SerializerStub _body;
 959                private OperationFormatter.MessageHeaderDescriptionTable _headerDescriptionTable;
 960                private MessageHeaderDescription _unknownHeaderDescription;
 961                private MessagePartDescriptionCollection _rpcEncodedTypedMessageBodyParts;
 962
 963                internal XmlMembersMapping BodyMapping
 964                {
 70965                    get { return _body.Mapping; }
 966                }
 967
 968                internal override XmlSerializer BodySerializer
 969                {
 40970                    get { return _body.GetSerializer(); }
 971                }
 972
 973                internal XmlMembersMapping HeadersMapping
 974                {
 0975                    get { return _headers.Mapping; }
 976                }
 977
 978                internal override XmlSerializer HeaderSerializer
 979                {
 42980                    get { return _headers.GetSerializer(); }
 981                }
 982
 983                internal override OperationFormatter.MessageHeaderDescriptionTable HeaderDescriptionTable
 984                {
 42985                    get { return _headerDescriptionTable; }
 986                }
 987
 988                internal override MessageHeaderDescription UnknownHeaderDescription
 989                {
 42990                    get { return _unknownHeaderDescription; }
 991                }
 992
 993                internal override MessagePartDescriptionCollection RpcEncodedTypedMessageBodyParts
 994                {
 40995                    get { return _rpcEncodedTypedMessageBodyParts; }
 996                }
 997
 998                internal void SetBody(SerializerStub body, MessagePartDescriptionCollection rpcEncodedTypedMessageBodyPa
 999                {
 1301000                    _body = body;
 1301001                    _rpcEncodedTypedMessageBodyParts = rpcEncodedTypedMessageBodyParts;
 1301002                }
 1003
 1004                internal void SetHeaders(SerializerStub headers)
 1005                {
 1301006                    _headers = headers;
 1301007                }
 1008
 1009                internal void SetHeaderDescriptionTable(OperationFormatter.MessageHeaderDescriptionTable headerDescripti
 1010                {
 1301011                    _headerDescriptionTable = headerDescriptionTable;
 1301012                }
 1013
 1014                internal void SetUnknownHeaderDescription(MessageHeaderDescription unknownHeaderDescription)
 1015                {
 01016                    _unknownHeaderDescription = unknownHeaderDescription;
 01017                }
 1018            }
 1019        }
 1020    }
 1021
 1022    internal static class XmlSerializerHelper
 1023    {
 1024        internal static XmlReflectionMember GetXmlReflectionMember(MessagePartDescription part, bool isRpc, bool isEncod
 1025        {
 1026            string ns = isRpc ? null : part.Namespace;
 1027            ICustomAttributeProvider additionalAttributesProvider = null;
 1028            if (isEncoded || part.AdditionalAttributesProvider is MemberInfo)
 1029                additionalAttributesProvider = part.AdditionalAttributesProvider;
 1030
 1031            XmlName memberName = string.IsNullOrEmpty(part.UniquePartName) ? null : new XmlName(part.UniquePartName, tru
 1032            XmlName elementName = part.XmlName;
 1033            return GetXmlReflectionMember(memberName, elementName, ns, part.Type, additionalAttributesProvider, part.Mul
 1034        }
 1035
 1036        internal static XmlReflectionMember GetXmlReflectionMember(XmlName memberName, XmlName elementName, string ns, T
 1037        {
 1038            if (isEncoded && isMultiple)
 1039            {
 1040                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFx
 1041            }
 1042
 1043            XmlReflectionMember member = new XmlReflectionMember
 1044            {
 1045                MemberName = (memberName ?? elementName).DecodedName,
 1046                MemberType = type
 1047            };
 1048            if (member.MemberType.IsByRef)
 1049            {
 1050                member.MemberType = member.MemberType.GetElementType();
 1051            }
 1052
 1053            if (isMultiple)
 1054            {
 1055                member.MemberType = member.MemberType.MakeArrayType();
 1056            }
 1057
 1058            if (additionalAttributesProvider != null)
 1059            {
 1060                if (isEncoded)
 1061                {
 1062                    member.SoapAttributes = new SoapAttributes(additionalAttributesProvider);
 1063                }
 1064                else
 1065                {
 1066                    member.XmlAttributes = new XmlAttributes(additionalAttributesProvider);
 1067                }
 1068            }
 1069
 1070            if (isEncoded)
 1071            {
 1072                if (member.SoapAttributes is null)
 1073                {
 1074                    member.SoapAttributes = new SoapAttributes();
 1075                }
 1076                else
 1077                {
 1078                    Type invalidAttributeType = null;
 1079                    if (member.SoapAttributes.SoapAttribute != null)
 1080                    {
 1081                        invalidAttributeType = typeof(SoapAttributeAttribute);
 1082                    }
 1083                    else if (member.SoapAttributes.SoapIgnore)
 1084                    {
 1085                        invalidAttributeType = typeof(SoapIgnoreAttribute);
 1086                    }
 1087                    else if (member.SoapAttributes.SoapType != null)
 1088                    {
 1089                        invalidAttributeType = typeof(SoapTypeAttribute);
 1090                    }
 1091
 1092                    if (invalidAttributeType != null)
 1093                    {
 1094                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma
 1095                    }
 1096                }
 1097
 1098                if (member.SoapAttributes.SoapElement == null)
 1099                {
 1100                    member.SoapAttributes.SoapElement = new SoapElementAttribute(elementName.DecodedName);
 1101                }
 1102            }
 1103            else
 1104            {
 1105                if (member.XmlAttributes is null)
 1106                {
 1107                    member.XmlAttributes = new XmlAttributes();
 1108                }
 1109                else
 1110                {
 1111                    Type invalidAttributeType = null;
 1112                    if (member.XmlAttributes.XmlAttribute != null)
 1113                    {
 1114                        invalidAttributeType = typeof(XmlAttributeAttribute);
 1115                    }
 1116                    else if (member.XmlAttributes.XmlAnyAttribute != null && !isWrapped)
 1117                    {
 1118                        invalidAttributeType = typeof(XmlAnyAttributeAttribute);
 1119                    }
 1120                    else if (member.XmlAttributes.XmlChoiceIdentifier != null)
 1121                    {
 1122                        invalidAttributeType = typeof(XmlChoiceIdentifierAttribute);
 1123                    }
 1124                    else if (member.XmlAttributes.XmlIgnore)
 1125                    {
 1126                        invalidAttributeType = typeof(XmlIgnoreAttribute);
 1127                    }
 1128                    else if (member.XmlAttributes.Xmlns)
 1129                    {
 1130                        invalidAttributeType = typeof(XmlNamespaceDeclarationsAttribute);
 1131                    }
 1132                    else if (member.XmlAttributes.XmlText != null)
 1133                    {
 1134                        invalidAttributeType = typeof(XmlTextAttribute);
 1135                    }
 1136                    else if (member.XmlAttributes.XmlEnum != null)
 1137                    {
 1138                        invalidAttributeType = typeof(XmlEnumAttribute);
 1139                    }
 1140
 1141                    if (invalidAttributeType != null)
 1142                    {
 1143                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma
 1144                    }
 1145
 1146                    if (member.XmlAttributes.XmlArray != null && isMultiple)
 1147                    {
 1148                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Forma
 1149                    }
 1150                }
 1151
 1152                bool isArray = member.MemberType.IsArray;
 1153                if ((isArray && !isMultiple && member.MemberType != typeof(byte[])) ||
 1154                   (!isArray && typeof(IEnumerable).IsAssignableFrom(member.MemberType) && member.MemberType != typeof(s
 1155                {
 1156                    if (member.XmlAttributes.XmlArray != null)
 1157                    {
 1158                        if (member.XmlAttributes.XmlArray.ElementName == string.Empty)
 1159                        {
 1160                            member.XmlAttributes.XmlArray.ElementName = elementName.DecodedName;
 1161                        }
 1162
 1163                        if (member.XmlAttributes.XmlArray.Namespace == null)
 1164                        {
 1165                            member.XmlAttributes.XmlArray.Namespace = ns;
 1166                        }
 1167                    }
 1168                    else if (HasNoXmlParameterAttributes(member.XmlAttributes))
 1169                    {
 1170                        member.XmlAttributes.XmlArray = new XmlArrayAttribute
 1171                        {
 1172                            ElementName = elementName.DecodedName,
 1173                            Namespace = ns
 1174                        };
 1175                    }
 1176                }
 1177                else
 1178                {
 1179                    if (member.XmlAttributes.XmlElements == null || member.XmlAttributes.XmlElements.Count == 0)
 1180                    {
 1181                        if (HasNoXmlParameterAttributes(member.XmlAttributes))
 1182                        {
 1183                            XmlElementAttribute elementAttribute = new XmlElementAttribute
 1184                            {
 1185                                ElementName = elementName.DecodedName,
 1186                                Namespace = ns
 1187                            };
 1188                            member.XmlAttributes.XmlElements.Add(elementAttribute);
 1189                        }
 1190                    }
 1191                    else
 1192                    {
 1193                        foreach (XmlElementAttribute elementAttribute in member.XmlAttributes.XmlElements)
 1194                        {
 1195                            if (elementAttribute.ElementName == string.Empty)
 1196                            {
 1197                                elementAttribute.ElementName = elementName.DecodedName;
 1198                            }
 1199
 1200                            if (elementAttribute.Namespace == null)
 1201                            {
 1202                                elementAttribute.Namespace = ns;
 1203                            }
 1204                        }
 1205                    }
 1206                }
 1207            }
 1208
 1209            return member;
 1210        }
 1211
 1212        private static bool HasNoXmlParameterAttributes(XmlAttributes xmlAttributes)
 1213        {
 1214            return xmlAttributes.XmlAnyAttribute == null &&
 1215                (xmlAttributes.XmlAnyElements == null || xmlAttributes.XmlAnyElements.Count == 0) &&
 1216                xmlAttributes.XmlArray == null &&
 1217                xmlAttributes.XmlAttribute == null &&
 1218                !xmlAttributes.XmlIgnore &&
 1219                xmlAttributes.XmlText == null &&
 1220                xmlAttributes.XmlChoiceIdentifier == null &&
 1221                (xmlAttributes.XmlElements == null || xmlAttributes.XmlElements.Count == 0) &&
 1222                !xmlAttributes.Xmlns;
 1223        }
 1224    }
 1225}

Methods/Properties

.ctor(CoreWCF.Description.OperationDescription)
.ctor(CoreWCF.Description.OperationDescription,CoreWCF.XmlSerializerFormatAttribute)
.ctor(CoreWCF.Description.OperationDescription,CoreWCF.XmlSerializerFormatAttribute,System.String)
.ctor(CoreWCF.Description.XmlSerializerOperationBehavior/Reflector/OperationReflector,System.Boolean)
OperationReflector()
IsBuiltInOperationBehavior()
XmlSerializerFormatAttribute()
CreateOperationFormatter(CoreWCF.Description.OperationDescription)
CreateOperationFormatter(CoreWCF.Description.OperationDescription,CoreWCF.XmlSerializerFormatAttribute)
AddBehaviors(CoreWCF.Description.ContractDescription)
AddBuiltInBehaviors(CoreWCF.Description.ContractDescription)
AddBehaviors(CoreWCF.Description.ContractDescription,System.Boolean)
CreateFormatter()
CreateFaultFormatter(CoreWCF.Collections.Generic.SynchronizedCollection`1<CoreWCF.Dispatcher.FaultContractInfo>)
CoreWCF.Description.IOperationBehavior.Validate(CoreWCF.Description.OperationDescription)
CoreWCF.Description.IOperationBehavior.AddBindingParameters(CoreWCF.Description.OperationDescription,CoreWCF.Channels.BindingParameterCollection)
CoreWCF.Description.IOperationBehavior.ApplyDispatchBehavior(CoreWCF.Description.OperationDescription,CoreWCF.Dispatcher.DispatchOperation)
CoreWCF.Description.IOperationBehavior.ApplyClientBehavior(CoreWCF.Description.OperationDescription,CoreWCF.Dispatcher.ClientOperation)
CoreWCF.Description.IWsdlExportExtension.ExportEndpoint(CoreWCF.Description.WsdlExporter,CoreWCF.Description.WsdlEndpointConversionContext)
CoreWCF.Description.IWsdlExportExtension.ExportContract(CoreWCF.Description.WsdlExporter,CoreWCF.Description.WsdlContractConversionContext)
GetXmlMappings()
.ctor(System.String,System.Type)
EnsureMessageInfos()
FindAttribute(CoreWCF.Description.OperationDescription)
ReflectOperation(CoreWCF.Description.OperationDescription)
ReflectOperation(CoreWCF.Description.OperationDescription,CoreWCF.XmlSerializerFormatAttribute)
.ctor(CoreWCF.Description.XmlSerializerOperationBehavior/Reflector,CoreWCF.Description.OperationDescription,CoreWCF.XmlSerializerFormatAttribute,System.Boolean)
SetUnknownHeaderInDescription(CoreWCF.Description.MessageHeaderDescription)
ContractName()
ContractNamespace()
Request()
Reply()
XmlSerializerFaultContractInfos()
EnsureMessageInfos()
GenerateXmlSerializerFaultContractInfos()
CreateMessageInfo(CoreWCF.Description.MessageDescription,System.String)
CreateHeaderDescriptionTable(CoreWCF.Description.MessageDescription,CoreWCF.Description.XmlSerializerOperationBehavior/Reflector/MessageInfo,System.Xml.Serialization.XmlMembersMapping)
LoadBodyMapping(CoreWCF.Description.MessageDescription,System.String,CoreWCF.Description.MessagePartDescriptionCollection&)
GetWrapperPart(CoreWCF.Description.MessageDescription)
GetWrappedParts(CoreWCF.Description.MessagePartDescription)
LoadHeadersMapping(CoreWCF.Description.MessageDescription,System.String)
ImportMembersMapping(System.String,System.String,System.Xml.Serialization.XmlReflectionMember[],System.Boolean,System.Boolean,System.String)
ImportFaultElement(CoreWCF.Description.FaultDescription,System.Xml.XmlQualifiedName&)
.ctor(System.String)
SoapImporter()
XmlImporter()
XmlMappings()
ImportMembersMapping(CoreWCF.Description.XmlName,System.String,System.Xml.Serialization.XmlReflectionMember[],System.Boolean,System.Boolean,System.Boolean,System.String)
ImportTypeMapping(System.Type,System.Boolean)
IncludeType(System.Type,System.Boolean)
.ctor(System.Type)
AddSerializer(System.Xml.Serialization.XmlMembersMapping)
GetSerializer(System.Int32)
GenerateSerializers()
CreateSerializersFromMappings(System.Xml.Serialization.XmlMapping[],System.Type)
.ctor(CoreWCF.Description.XmlSerializerOperationBehavior/Reflector/SerializerGenerationContext,System.Xml.Serialization.XmlMembersMapping,System.Int32)
GetSerializer()
.ctor(CoreWCF.Dispatcher.FaultContractInfo,CoreWCF.Description.XmlSerializerOperationBehavior/Reflector/SerializerStub,System.Xml.XmlQualifiedName)
FaultContractInfo()
FaultContractElementName()
Serializer()
BodyMapping()
BodySerializer()
HeadersMapping()
HeaderSerializer()
HeaderDescriptionTable()
UnknownHeaderDescription()
RpcEncodedTypedMessageBodyParts()
SetBody(CoreWCF.Description.XmlSerializerOperationBehavior/Reflector/SerializerStub,CoreWCF.Description.MessagePartDescriptionCollection)
SetHeaders(CoreWCF.Description.XmlSerializerOperationBehavior/Reflector/SerializerStub)
SetHeaderDescriptionTable(CoreWCF.Dispatcher.OperationFormatter/MessageHeaderDescriptionTable)
SetUnknownHeaderDescription(CoreWCF.Description.MessageHeaderDescription)