< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Dispatcher.OperationFormatter
Assembly: CoreWCF.Primitives
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Dispatcher/OperationFormatter.cs
Line coverage
75%
Covered lines: 250
Uncovered lines: 82
Coverable lines: 332
Total lines: 848
Line coverage: 75.3%
Branch coverage
70%
Covered branches: 96
Total branches: 136
Branch coverage: 70.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.ctor(...)100%66100%
WriteBodyAttributes(...)100%11100%
AddToDictionary(...)100%11100%
DeserializeReply(...)0%660%
CreateTypedMessageInstance(...)100%1160%
DeserializeRequest(...)66.66%6650%
DeserializeBodyContents(...)100%44100%
SerializeRequest(...)0%880%
SerializeReply(...)62.5%8888.23%
SetupStreamAndMessageDescription(...)100%22100%
SerializeBodyContentsAsync()100%22100%
SerializeBodyContents(...)100%22100%
AddPropertiesToMessage(...)100%22100%
AddPropertiesToMessageCore(...)100%44100%
GetPropertiesFromMessage(...)100%22100%
GetPropertiesFromMessageCore(...)75%4485.71%
GetContentOfMessageHeaderOfT(...)50%4483.33%
IsValidReturnValue(...)100%22100%
AddToDictionary(...)100%22100%
Validate(...)81.81%222280%
GetActions(...)90%101092.85%
TraceAndSkipElement(...)100%11100%
.ctor(...)80%101091.66%
GetValue(...)100%22100%
SetValue(...)100%22100%
GetTypedMessageParts(...)100%22100%
SetTypedMessageParts(...)100%22100%
.ctor(...)100%11100%
.ctor(...)100%110%
.ctor(...)100%11100%
OnWriteStartBody(...)100%11100%
OnCreateBufferedCopy(...)50%2283.33%
.ctor(...)100%11100%
AreParametersBuffered(...)50%22100%
OnWriteBodyContents(...)100%11100%
OnWriteBodyContentsAsync(...)100%11100%
.ctor(...)100%11100%
CreateMessage()50%4471.42%
.ctor(...)50%2280%
IsMessageVersionSupported(...)100%11100%
OnWriteStartHeader(...)50%44100%
OnWriteHeaderAttributes(...)100%110%
.ctor(...)100%11100%
OnWriteHeaderAttributes(...)100%11100%
OnWriteHeaderContents(...)100%11100%
.ctor(...)100%11100%
.cctor()100%11100%
.ctor()100%11100%
Equals(...)50%22100%
GetHashCode(...)100%11100%
.ctor()100%11100%
Add(...)100%11100%
Get(...)100%22100%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.Primitives/src/CoreWCF/Dispatcher/OperationFormatter.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.Reflection;
 7using System.Runtime.Serialization;
 8using System.Threading.Tasks;
 9using System.Xml;
 10using CoreWCF.Channels;
 11using CoreWCF.Description;
 12using CoreWCF.Diagnostics;
 13
 14namespace CoreWCF.Dispatcher
 15{
 16    public abstract class OperationFormatter : IClientMessageFormatter, IDispatchMessageFormatter
 17    {
 18        private readonly XmlDictionaryString _action;
 19        private readonly XmlDictionaryString _replyAction;
 20        internal StreamFormatter requestStreamFormatter, replyStreamFormatter;
 21
 86722        public OperationFormatter(OperationDescription description, bool isRpc, bool isEncoded)
 23        {
 86724            Validate(description, isRpc, isEncoded);
 86725            RequestDescription = description.Messages[0];
 86726            if (description.Messages.Count == 2)
 27            {
 86328                ReplyDescription = description.Messages[1];
 29            }
 30
 86731            int stringCount = 3 + RequestDescription.Body.Parts.Count;
 86732            if (ReplyDescription != null)
 33            {
 86334                stringCount += 2 + ReplyDescription.Body.Parts.Count;
 35            }
 36
 86737            Dictionary = new XmlDictionary(stringCount * 2);
 86738            GetActions(description, Dictionary, out _action, out _replyAction);
 86739            OperationName = description.Name;
 86740            requestStreamFormatter = StreamFormatter.Create(RequestDescription, OperationName, true/*isRequest*/);
 86741            if (ReplyDescription != null)
 42            {
 86343                replyStreamFormatter = StreamFormatter.Create(ReplyDescription, OperationName, false/*isResponse*/);
 44            }
 86745        }
 46
 47        protected abstract void AddHeadersToMessage(Message message, MessageDescription messageDescription, object[] par
 48        protected abstract void SerializeBody(XmlDictionaryWriter writer, MessageVersion version, string action, Message
 49        protected abstract void GetHeadersFromMessage(Message message, MessageDescription messageDescription, object[] p
 50        protected abstract object DeserializeBody(XmlDictionaryReader reader, MessageVersion version, string action, Mes
 51
 52        protected virtual void WriteBodyAttributes(XmlDictionaryWriter writer, MessageVersion messageVersion)
 53        {
 14654        }
 55
 56        internal string RequestAction
 57        {
 58            get
 59            {
 31260                if (_action != null)
 61                {
 31262                    return _action.Value;
 63                }
 64
 065                return null;
 66            }
 67        }
 68        internal string ReplyAction
 69        {
 70            get
 71            {
 072                if (_replyAction != null)
 73                {
 074                    return _replyAction.Value;
 75                }
 76
 077                return null;
 78            }
 79        }
 80
 781981        protected XmlDictionary Dictionary { get; }
 82
 173083        protected string OperationName { get; }
 84
 577185        protected MessageDescription ReplyDescription { get; }
 86
 328587        protected MessageDescription RequestDescription { get; }
 88
 89        protected XmlDictionaryString AddToDictionary(string s)
 90        {
 695291            return AddToDictionary(Dictionary, s);
 92        }
 93
 94        public object DeserializeReply(Message message, object[] parameters)
 95        {
 096            if (message == null)
 97            {
 098                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(message));
 99            }
 100
 0101            if (parameters == null)
 102            {
 0103                throw TraceUtility.ThrowHelperError(new ArgumentNullException(nameof(parameters)), message);
 104            }
 105
 106            try
 107            {
 0108                object result = null;
 0109                if (ReplyDescription.IsTypedMessage)
 110                {
 0111                    object typeMessageInstance = CreateTypedMessageInstance(ReplyDescription.MessageType);
 0112                    TypedMessageParts typedMessageParts = new TypedMessageParts(typeMessageInstance, ReplyDescription);
 0113                    object[] parts = new object[typedMessageParts.Count];
 114
 0115                    GetPropertiesFromMessage(message, ReplyDescription, parts);
 0116                    GetHeadersFromMessage(message, ReplyDescription, parts, false/*isRequest*/);
 0117                    DeserializeBodyContents(message, parts, false/*isRequest*/);
 118
 119                    // copy values into the actual field/properties
 0120                    typedMessageParts.SetTypedMessageParts(parts);
 121
 0122                    result = typeMessageInstance;
 123                }
 124                else
 125                {
 0126                    GetPropertiesFromMessage(message, ReplyDescription, parameters);
 0127                    GetHeadersFromMessage(message, ReplyDescription, parameters, false/*isRequest*/);
 0128                    result = DeserializeBodyContents(message, parameters, false/*isRequest*/);
 129                }
 0130                return result;
 131            }
 0132            catch (XmlException xe)
 133            {
 0134                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
 0135                    SR.Format(SR.SFxErrorDeserializingReplyBodyMore, OperationName, xe.Message), xe));
 136            }
 0137            catch (FormatException fe)
 138            {
 0139                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
 0140                    SR.Format(SR.SFxErrorDeserializingReplyBodyMore, OperationName, fe.Message), fe));
 141            }
 0142            catch (SerializationException se)
 143            {
 0144                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
 0145                    SR.Format(SR.SFxErrorDeserializingReplyBodyMore, OperationName, se.Message), se));
 146            }
 0147        }
 148
 149        private static object CreateTypedMessageInstance(Type messageContractType)
 150        {
 151            try
 152            {
 17153                object typeMessageInstance = Activator.CreateInstance(messageContractType);
 17154                return typeMessageInstance;
 155            }
 0156            catch (MissingMethodException mme)
 157            {
 0158                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFx
 159            }
 17160        }
 161
 162        public void DeserializeRequest(Message message, object[] parameters)
 163        {
 175164            if (message == null)
 165            {
 0166                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(message));
 167            }
 168
 175169            if (parameters == null)
 170            {
 0171                throw TraceUtility.ThrowHelperError(new ArgumentNullException(nameof(parameters)), message);
 172            }
 173
 174            try
 175            {
 175176                if (RequestDescription.IsTypedMessage)
 177                {
 17178                    object typeMessageInstance = CreateTypedMessageInstance(RequestDescription.MessageType);
 17179                    TypedMessageParts typedMessageParts = new TypedMessageParts(typeMessageInstance, RequestDescription)
 17180                    object[] parts = new object[typedMessageParts.Count];
 181
 17182                    GetPropertiesFromMessage(message, RequestDescription, parts);
 17183                    GetHeadersFromMessage(message, RequestDescription, parts, true/*isRequest*/);
 17184                    DeserializeBodyContents(message, parts, true/*isRequest*/);
 185
 186                    // copy values into the actual field/properties
 17187                    typedMessageParts.SetTypedMessageParts(parts);
 188
 17189                    parameters[0] = typeMessageInstance;
 190                }
 191                else
 192                {
 158193                    GetPropertiesFromMessage(message, RequestDescription, parameters);
 158194                    GetHeadersFromMessage(message, RequestDescription, parameters, true/*isRequest*/);
 158195                    DeserializeBodyContents(message, parameters, true/*isRequest*/);
 196                }
 175197            }
 0198            catch (XmlException xe)
 199            {
 0200                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
 0201                    NetDispatcherFaultException.CreateDeserializationFailedFault(
 0202                        SR.Format(SR.SFxErrorDeserializingRequestBodyMore, OperationName, xe.Message),
 0203                        xe));
 204            }
 0205            catch (FormatException fe)
 206            {
 0207                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
 0208                    NetDispatcherFaultException.CreateDeserializationFailedFault(
 0209                        SR.Format(SR.SFxErrorDeserializingRequestBodyMore, OperationName, fe.Message),
 0210                        fe));
 211            }
 0212            catch (SerializationException se)
 213            {
 0214                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(
 0215                    SR.Format(SR.SFxErrorDeserializingRequestBodyMore, OperationName, se.Message),
 0216                    se));
 217            }
 175218        }
 219
 220        private object DeserializeBodyContents(Message message, object[] parameters, bool isRequest)
 221        {
 175222            SetupStreamAndMessageDescription(isRequest, out StreamFormatter streamFormatter, out MessageDescription mess
 223
 175224            if (streamFormatter != null)
 225            {
 16226                object retVal = null;
 16227                streamFormatter.Deserialize(parameters, ref retVal, message);
 16228                return retVal;
 229            }
 230
 159231            if (message.IsEmpty)
 232            {
 2233                return null;
 234            }
 235            else
 236            {
 157237                XmlDictionaryReader reader = message.GetReaderAtBodyContents();
 157238                using (reader)
 239                {
 157240                    object body = DeserializeBody(reader, message.Version, RequestAction, messageDescription, parameters
 157241                    message.ReadFromBodyContentsToEnd(reader);
 157242                    return body;
 243                }
 244            }
 157245        }
 246
 247        public Message SerializeRequest(MessageVersion messageVersion, object[] parameters)
 248        {
 0249            if (messageVersion == null)
 250            {
 0251                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(messageVersion));
 252            }
 253
 0254            if (parameters == null)
 255            {
 0256                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(parameters));
 257            }
 258
 259            object[] parts;
 0260            if (RequestDescription.IsTypedMessage)
 261            {
 0262                TypedMessageParts typedMessageParts = new TypedMessageParts(parameters[0], RequestDescription);
 263
 264                // copy values from the actual field/properties
 0265                parts = new object[typedMessageParts.Count];
 0266                typedMessageParts.GetTypedMessageParts(parts);
 267            }
 268            else
 269            {
 0270                parts = parameters;
 271            }
 0272            Message msg = new OperationFormatterMessage(this, messageVersion,
 0273                _action == null ? null : ActionHeader.Create(_action, messageVersion.Addressing),
 0274                parts, null, true/*isRequest*/);
 0275            AddPropertiesToMessage(msg, RequestDescription, parts);
 0276            AddHeadersToMessage(msg, RequestDescription, parts, true /*isRequest*/);
 277
 0278            return msg;
 279        }
 280
 281        public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result)
 282        {
 167283            if (messageVersion == null)
 284            {
 0285                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(messageVersion));
 286            }
 287
 167288            if (parameters == null)
 289            {
 0290                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(parameters));
 291            }
 292
 293            object[] parts;
 294            object resultPart;
 167295            if (ReplyDescription.IsTypedMessage)
 296            {
 297                // If the response is a typed message then it must
 298                // me the response (as opposed to an out param).  We will
 299                // serialize the response in the exact same way that we
 300                // would serialize a bunch of outs (with no return value).
 301
 13302                TypedMessageParts typedMessageParts = new TypedMessageParts(result, ReplyDescription);
 303
 304                // make a copy of the list so that we have the actual values of the field/properties
 13305                parts = new object[typedMessageParts.Count];
 13306                typedMessageParts.GetTypedMessageParts(parts);
 307
 13308                resultPart = null;
 309            }
 310            else
 311            {
 154312                parts = parameters;
 154313                resultPart = result;
 314            }
 315
 167316            Message msg = new OperationFormatterMessage(this, messageVersion,
 167317                _replyAction == null ? null : ActionHeader.Create(_replyAction, messageVersion.Addressing),
 167318                parts, resultPart, false/*isRequest*/);
 167319            AddPropertiesToMessage(msg, ReplyDescription, parts);
 167320            AddHeadersToMessage(msg, ReplyDescription, parts, false /*isRequest*/);
 167321            return msg;
 322        }
 323
 324        private void SetupStreamAndMessageDescription(bool isRequest, out StreamFormatter streamFormatter, out MessageDe
 325        {
 342326            if (isRequest)
 327            {
 175328                streamFormatter = requestStreamFormatter;
 175329                messageDescription = RequestDescription;
 330            }
 331            else
 332            {
 167333                streamFormatter = replyStreamFormatter;
 167334                messageDescription = ReplyDescription;
 335            }
 167336        }
 337
 338        private async Task SerializeBodyContentsAsync(XmlDictionaryWriter writer, MessageVersion version, object[] param
 339        {
 20340            SetupStreamAndMessageDescription(isRequest, out StreamFormatter streamFormatter, out MessageDescription mess
 341
 20342            if (streamFormatter != null)
 343            {
 4344                await streamFormatter.SerializeAsync(writer, parameters, returnValue);
 4345                return;
 346            }
 347
 16348            SerializeBody(writer, version, RequestAction, messageDescription, returnValue, parameters, isRequest);
 19349        }
 350
 351        private void SerializeBodyContents(XmlDictionaryWriter writer, MessageVersion version, object[] parameters, obje
 352        {
 147353            SetupStreamAndMessageDescription(isRequest, out StreamFormatter streamFormatter, out MessageDescription mess
 354
 147355            if (streamFormatter != null)
 356            {
 8357                streamFormatter.Serialize(writer, parameters, returnValue);
 8358                return;
 359            }
 360
 139361            SerializeBody(writer, version, RequestAction, messageDescription, returnValue, parameters, isRequest);
 139362        }
 363
 364        private void AddPropertiesToMessage(Message message, MessageDescription messageDescription, object[] parameters)
 365        {
 167366            if (messageDescription.Properties.Count > 0)
 367            {
 3368                AddPropertiesToMessageCore(message, messageDescription, parameters);
 369            }
 167370        }
 371
 372        private void AddPropertiesToMessageCore(Message message, MessageDescription messageDescription, object[] paramet
 373        {
 3374            MessageProperties properties = message.Properties;
 3375            MessagePropertyDescriptionCollection propertyDescriptions = messageDescription.Properties;
 12376            for (int i = 0; i < propertyDescriptions.Count; i++)
 377            {
 3378                MessagePropertyDescription propertyDescription = propertyDescriptions[i];
 3379                object parameter = parameters[propertyDescription.Index];
 3380                if (null != parameter)
 381                {
 1382                    properties.Add(propertyDescription.Name, parameter);
 383                }
 384            }
 3385        }
 386
 387        private void GetPropertiesFromMessage(Message message, MessageDescription messageDescription, object[] parameter
 388        {
 175389            if (messageDescription.Properties.Count > 0)
 390            {
 2391                GetPropertiesFromMessageCore(message, messageDescription, parameters);
 392            }
 175393        }
 394
 395        private void GetPropertiesFromMessageCore(Message message, MessageDescription messageDescription, object[] param
 396        {
 2397            MessageProperties properties = message.Properties;
 2398            MessagePropertyDescriptionCollection propertyDescriptions = messageDescription.Properties;
 8399            for (int i = 0; i < propertyDescriptions.Count; i++)
 400            {
 2401                MessagePropertyDescription propertyDescription = propertyDescriptions[i];
 2402                if (properties.ContainsKey(propertyDescription.Name))
 403                {
 0404                    parameters[propertyDescription.Index] = properties[propertyDescription.Name];
 405                }
 406            }
 2407        }
 408
 409        internal static object GetContentOfMessageHeaderOfT(MessageHeaderDescription headerDescription, object parameter
 410        {
 8411            actor = headerDescription.Actor;
 8412            mustUnderstand = headerDescription.MustUnderstand;
 8413            relay = headerDescription.Relay;
 414
 8415            if (headerDescription.TypedHeader && parameterValue != null)
 416            {
 0417                parameterValue = TypedHeaderManager.GetContent(headerDescription.Type, parameterValue, out mustUnderstan
 418            }
 419
 8420            return parameterValue;
 421        }
 422
 423        internal static bool IsValidReturnValue(MessagePartDescription returnValue)
 424        {
 3912425            return (returnValue != null) && (returnValue.Type != typeof(void));
 426        }
 427
 428        internal static XmlDictionaryString AddToDictionary(XmlDictionary dictionary, string s)
 429        {
 12306430            if (!dictionary.TryLookup(s, out XmlDictionaryString dictionaryString))
 431            {
 9231432                dictionaryString = dictionary.Add(s);
 433            }
 12306434            return dictionaryString;
 435        }
 436
 437        internal static void Validate(OperationDescription operation, bool isRpc, bool isEncoded)
 438        {
 3027439            if (isEncoded && !isRpc)
 440            {
 0441                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFx
 442            }
 443
 3027444            bool hasVoid = false;
 3027445            bool hasTypedOrUntypedMessage = false;
 3027446            bool hasParameter = false;
 17534447            for (int i = 0; i < operation.Messages.Count; i++)
 448            {
 5740449                MessageDescription message = operation.Messages[i];
 5740450                if (message.IsTypedMessage || message.IsUntypedMessage)
 451                {
 232452                    if (isRpc && operation.IsValidateRpcWrapperName)
 453                    {
 8454                        if (!isEncoded)
 455                        {
 0456                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.F
 457                        }
 458                    }
 232459                    hasTypedOrUntypedMessage = true;
 460                }
 5508461                else if (message.IsVoid)
 462                {
 773463                    hasVoid = true;
 464                }
 465                else
 466                {
 4735467                    hasParameter = true;
 468                }
 469            }
 3027470            if (hasParameter && hasTypedOrUntypedMessage)
 471            {
 0472                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFx
 473            }
 474
 3027475            if (isRpc && hasTypedOrUntypedMessage && hasVoid)
 476            {
 0477                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.SFx
 478            }
 3027479        }
 480
 481        internal static void GetActions(OperationDescription description, XmlDictionary dictionary, out XmlDictionaryStr
 482        {
 483            string actionString, replyActionString;
 2839484            actionString = description.Messages[0].Action;
 2839485            if (actionString == MessageHeaders.WildcardAction)
 486            {
 0487                actionString = null;
 488            }
 489
 2839490            if (!description.IsOneWay)
 491            {
 2525492                replyActionString = description.Messages[1].Action;
 493            }
 494            else
 495            {
 314496                replyActionString = null;
 497            }
 498
 2839499            if (replyActionString == MessageHeaders.WildcardAction)
 500            {
 10501                replyActionString = null;
 502            }
 503
 2839504            action = replyAction = null;
 2839505            if (actionString != null)
 506            {
 2839507                action = AddToDictionary(dictionary, actionString);
 508            }
 509
 2839510            if (replyActionString != null)
 511            {
 2515512                replyAction = AddToDictionary(dictionary, replyActionString);
 513            }
 2839514        }
 515
 516        internal static void TraceAndSkipElement(XmlReader xmlReader)
 517        {
 518            //if (DiagnosticUtility.ShouldTraceVerbose)
 519            //{
 520            //    TraceUtility.TraceEvent(TraceEventType.Verbose, TraceCode.ElementIgnored, SR.SFxTraceCodeElementIgnore
 521            //}
 4522            xmlReader.Skip();
 4523        }
 524
 525        private class TypedMessageParts
 526        {
 527            private readonly object _instance;
 528            private readonly MemberInfo[] _members;
 529
 30530            public TypedMessageParts(object instance, MessageDescription description)
 531            {
 30532                if (description == null)
 533                {
 0534                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullException(nameof(descripti
 535                }
 536
 30537                _members = new MemberInfo[description.Body.Parts.Count + description.Properties.Count + description.Head
 538
 100539                foreach (MessagePartDescription part in description.Headers)
 540                {
 20541                    _members[part.Index] = part.MemberInfo;
 542                }
 543
 70544                foreach (MessagePartDescription part in description.Properties)
 545                {
 5546                    _members[part.Index] = part.MemberInfo;
 547                }
 548
 132549                foreach (MessagePartDescription part in description.Body.Parts)
 550                {
 36551                    _members[part.Index] = part.MemberInfo;
 552                }
 553
 30554                _instance = instance ?? throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentNullExcept
 30555            }
 556
 557            private object GetValue(int index)
 558            {
 29559                MemberInfo memberInfo = _members[index];
 29560                PropertyInfo propertyInfo = memberInfo as PropertyInfo;
 29561                if (propertyInfo != null)
 562                {
 8563                    return propertyInfo.GetValue(_instance, null);
 564                }
 565                else
 566                {
 21567                    return ((FieldInfo)memberInfo).GetValue(_instance);
 568                }
 569            }
 570
 571            private void SetValue(object value, int index)
 572            {
 32573                MemberInfo memberInfo = _members[index];
 32574                PropertyInfo propertyInfo = memberInfo as PropertyInfo;
 32575                if (propertyInfo != null)
 576                {
 7577                    propertyInfo.SetValue(_instance, value, null);
 578                }
 579                else
 580                {
 25581                    ((FieldInfo)memberInfo).SetValue(_instance, value);
 582                }
 25583            }
 584
 585            internal void GetTypedMessageParts(object[] values)
 586            {
 84587                for (int i = 0; i < _members.Length; i++)
 588                {
 29589                    values[i] = GetValue(i);
 590                }
 13591            }
 592
 593            internal void SetTypedMessageParts(object[] values)
 594            {
 98595                for (int i = 0; i < _members.Length; i++)
 596                {
 32597                    SetValue(values[i], i);
 598                }
 17599            }
 600
 601            internal int Count
 602            {
 30603                get { return _members.Length; }
 604            }
 605        }
 606
 607        internal class OperationFormatterMessage : BodyWriterMessage
 608        {
 609            private readonly OperationFormatter _operationFormatter;
 610            public OperationFormatterMessage(OperationFormatter operationFormatter, MessageVersion version, ActionHeader
 611               object[] parameters, object returnValue, bool isRequest)
 167612                : base(version, action, new OperationFormatterBodyWriter(operationFormatter, version, parameters, return
 613            {
 167614                _operationFormatter = operationFormatter;
 167615            }
 616
 617
 0618            public OperationFormatterMessage(MessageVersion version, string action, BodyWriter bodyWriter) : base(versio
 619
 620            private OperationFormatterMessage(MessageHeaders headers, KeyValuePair<string, object>[] properties, Operati
 11621                : base(headers, properties, bodyWriter)
 622            {
 11623                _operationFormatter = bodyWriter.OperationFormatter;
 11624            }
 625
 626            protected override void OnWriteStartBody(XmlDictionaryWriter writer)
 627            {
 167628                base.OnWriteStartBody(writer);
 167629                _operationFormatter.WriteBodyAttributes(writer, Version);
 167630            }
 631
 632            protected override MessageBuffer OnCreateBufferedCopy(int maxBufferSize)
 633            {
 634                BodyWriter bufferedBodyWriter;
 11635                if (BodyWriter.IsBuffered)
 636                {
 11637                    bufferedBodyWriter = BodyWriter;
 638                }
 639                else
 640                {
 0641                    bufferedBodyWriter = BodyWriter.CreateBufferedCopy(maxBufferSize);
 642                }
 11643                KeyValuePair<string, object>[] properties = new KeyValuePair<string, object>[base.Properties.Count];
 11644                ((ICollection<KeyValuePair<string, object>>)base.Properties).CopyTo(properties, 0);
 11645                return new OperationFormatterMessageBuffer(base.Headers, properties, bufferedBodyWriter);
 646            }
 647
 648            private class OperationFormatterBodyWriter : BodyWriter
 649            {
 650                private readonly bool _isRequest;
 651                private readonly object[] _parameters;
 652                private readonly object _returnValue;
 653                private readonly MessageVersion _version;
 654
 655                public OperationFormatterBodyWriter(OperationFormatter operationFormatter, MessageVersion version,
 656                    object[] parameters, object returnValue, bool isRequest)
 167657                    : base(AreParametersBuffered(isRequest, operationFormatter))
 658                {
 167659                    _parameters = parameters;
 167660                    _returnValue = returnValue;
 167661                    _isRequest = isRequest;
 167662                    OperationFormatter = operationFormatter;
 167663                    _version = version;
 167664                }
 665
 666                private object ThisLock
 667                {
 147668                    get { return this; }
 669                }
 670
 671                private static bool AreParametersBuffered(bool isRequest, OperationFormatter operationFormatter)
 672                {
 167673                    StreamFormatter streamFormatter = isRequest ? operationFormatter.requestStreamFormatter : operationF
 167674                    return streamFormatter == null;
 675                }
 676
 677                protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
 678                {
 147679                    lock (ThisLock)
 680                    {
 147681                        OperationFormatter.SerializeBodyContents(writer, _version, _parameters, _returnValue, _isRequest
 147682                    }
 147683                }
 684
 685                protected override Task OnWriteBodyContentsAsync(XmlDictionaryWriter writer)
 686                {
 20687                    return OperationFormatter.SerializeBodyContentsAsync(writer, _version, _parameters, _returnValue, _i
 688                }
 689
 178690                internal OperationFormatter OperationFormatter { get; }
 691            }
 692
 693            private class OperationFormatterMessageBuffer : BodyWriterMessageBuffer
 694            {
 695                public OperationFormatterMessageBuffer(MessageHeaders headers,
 696                    KeyValuePair<string, object>[] properties, BodyWriter bodyWriter)
 11697                    : base(headers, properties, bodyWriter)
 698                {
 11699                }
 700
 701                public override Message CreateMessage()
 702                {
 11703                    if (!(BodyWriter is OperationFormatterBodyWriter operationFormatterBodyWriter))
 704                    {
 0705                        return base.CreateMessage();
 706                    }
 707
 11708                    lock (ThisLock)
 709                    {
 11710                        if (Closed)
 711                        {
 0712                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateBufferDisposedException());
 713                        }
 714
 11715                        return new OperationFormatterMessage(Headers, Properties, operationFormatterBodyWriter);
 716                    }
 11717                }
 718            }
 719        }
 720
 721        internal abstract class OperationFormatterHeader : MessageHeader
 722        {
 723            private readonly MessageHeader _innerHeader; //use innerHeader to handle versionSupported, actor/role handli
 724
 4725            public OperationFormatterHeader(OperationFormatter operationFormatter, MessageVersion version, string name, 
 726            {
 4727                if (actor != null)
 728                {
 0729                    _innerHeader = CreateHeader(name, ns, null/*headerValue*/, mustUnderstand, actor, relay);
 730                }
 731                else
 732                {
 4733                    _innerHeader = CreateHeader(name, ns, null/*headerValue*/, mustUnderstand, "", relay);
 734                }
 4735            }
 736
 737
 738            public override bool IsMessageVersionSupported(MessageVersion messageVersion)
 739            {
 4740                return _innerHeader.IsMessageVersionSupported(messageVersion);
 741            }
 742
 743
 744            public override string Name
 745            {
 4746                get { return _innerHeader.Name; }
 747            }
 748
 749            public override string Namespace
 750            {
 20751                get { return _innerHeader.Namespace; }
 752            }
 753
 754            public override bool MustUnderstand
 755            {
 8756                get { return _innerHeader.MustUnderstand; }
 757            }
 758
 759            public override bool Relay
 760            {
 4761                get { return _innerHeader.Relay; }
 762            }
 763
 764            public override string Actor
 765            {
 4766                get { return _innerHeader.Actor; }
 767            }
 768
 769            protected override void OnWriteStartHeader(XmlDictionaryWriter writer, MessageVersion messageVersion)
 770            {
 771                //Prefix needed since there may be xsi:type attribute at toplevel with qname value where ns = ""
 4772                writer.WriteStartElement((Namespace == null || Namespace.Length == 0) ? string.Empty : "h", Name, Namesp
 4773                OnWriteHeaderAttributes(writer, messageVersion);
 4774            }
 775
 776            protected virtual void OnWriteHeaderAttributes(XmlDictionaryWriter writer, MessageVersion messageVersion)
 777            {
 0778                WriteHeaderAttributes(writer, messageVersion);
 0779            }
 780        }
 781
 782        internal class XmlElementMessageHeader : OperationFormatterHeader
 783        {
 784            protected XmlElement headerValue;
 785            public XmlElementMessageHeader(OperationFormatter operationFormatter, MessageVersion version, string name, s
 4786                base(operationFormatter, version, name, ns, mustUnderstand, actor, relay)
 787            {
 4788                this.headerValue = headerValue;
 4789            }
 790
 791            protected override void OnWriteHeaderAttributes(XmlDictionaryWriter writer, MessageVersion messageVersion)
 792            {
 4793                WriteHeaderAttributes(writer, messageVersion);
 4794                XmlDictionaryReader nodeReader = XmlDictionaryReader.CreateDictionaryReader(new XmlNodeReader(headerValu
 4795                nodeReader.MoveToContent();
 4796                writer.WriteAttributes(nodeReader, false);
 4797            }
 798
 799            protected override void OnWriteHeaderContents(XmlDictionaryWriter writer, MessageVersion messageVersion)
 800            {
 4801                headerValue.WriteContentTo(writer);
 4802            }
 803        }
 804        internal struct QName
 805        {
 806            internal string Name;
 807            internal string Namespace;
 808            internal QName(string name, string ns)
 809            {
 228810                Name = name;
 228811                Namespace = ns;
 228812            }
 813        }
 814        internal class QNameComparer : IEqualityComparer<QName>
 815        {
 4816            internal static QNameComparer Singleton = new QNameComparer();
 817
 8818            private QNameComparer() { }
 819
 820            public bool Equals(QName x, QName y)
 821            {
 16822                return x.Name == y.Name && x.Namespace == y.Namespace;
 823            }
 824
 825            public int GetHashCode(QName obj)
 826            {
 228827                return obj.Name.GetHashCode();
 828            }
 829        }
 830        internal class MessageHeaderDescriptionTable : Dictionary<QName, MessageHeaderDescription>
 831        {
 3488832            internal MessageHeaderDescriptionTable() : base(QNameComparer.Singleton) { }
 833            internal void Add(string name, string ns, MessageHeaderDescription message)
 834            {
 190835                Add(new QName(name, ns), message);
 190836            }
 837            internal MessageHeaderDescription Get(string name, string ns)
 838            {
 38839                if (TryGetValue(new QName(name, ns), out MessageHeaderDescription message))
 840                {
 16841                    return message;
 842                }
 843
 22844                return null;
 845            }
 846        }
 847    }
 848}

Methods/Properties

.ctor(CoreWCF.Description.OperationDescription,System.Boolean,System.Boolean)
WriteBodyAttributes(System.Xml.XmlDictionaryWriter,CoreWCF.Channels.MessageVersion)
RequestAction()
ReplyAction()
Dictionary()
OperationName()
ReplyDescription()
RequestDescription()
AddToDictionary(System.String)
DeserializeReply(CoreWCF.Channels.Message,System.Object[])
CreateTypedMessageInstance(System.Type)
DeserializeRequest(CoreWCF.Channels.Message,System.Object[])
DeserializeBodyContents(CoreWCF.Channels.Message,System.Object[],System.Boolean)
SerializeRequest(CoreWCF.Channels.MessageVersion,System.Object[])
SerializeReply(CoreWCF.Channels.MessageVersion,System.Object[],System.Object)
SetupStreamAndMessageDescription(System.Boolean,CoreWCF.Dispatcher.StreamFormatter&,CoreWCF.Description.MessageDescription&)
SerializeBodyContentsAsync()
SerializeBodyContents(System.Xml.XmlDictionaryWriter,CoreWCF.Channels.MessageVersion,System.Object[],System.Object,System.Boolean)
AddPropertiesToMessage(CoreWCF.Channels.Message,CoreWCF.Description.MessageDescription,System.Object[])
AddPropertiesToMessageCore(CoreWCF.Channels.Message,CoreWCF.Description.MessageDescription,System.Object[])
GetPropertiesFromMessage(CoreWCF.Channels.Message,CoreWCF.Description.MessageDescription,System.Object[])
GetPropertiesFromMessageCore(CoreWCF.Channels.Message,CoreWCF.Description.MessageDescription,System.Object[])
GetContentOfMessageHeaderOfT(CoreWCF.Description.MessageHeaderDescription,System.Object,System.Boolean&,System.Boolean&,System.String&)
IsValidReturnValue(CoreWCF.Description.MessagePartDescription)
AddToDictionary(System.Xml.XmlDictionary,System.String)
Validate(CoreWCF.Description.OperationDescription,System.Boolean,System.Boolean)
GetActions(CoreWCF.Description.OperationDescription,System.Xml.XmlDictionary,System.Xml.XmlDictionaryString&,System.Xml.XmlDictionaryString&)
TraceAndSkipElement(System.Xml.XmlReader)
.ctor(System.Object,CoreWCF.Description.MessageDescription)
GetValue(System.Int32)
SetValue(System.Object,System.Int32)
GetTypedMessageParts(System.Object[])
SetTypedMessageParts(System.Object[])
Count()
.ctor(CoreWCF.Dispatcher.OperationFormatter,CoreWCF.Channels.MessageVersion,CoreWCF.Channels.ActionHeader,System.Object[],System.Object,System.Boolean)
.ctor(CoreWCF.Channels.MessageVersion,System.String,CoreWCF.Channels.BodyWriter)
.ctor(CoreWCF.Channels.MessageHeaders,System.Collections.Generic.KeyValuePair`2<System.String,System.Object>[],CoreWCF.Dispatcher.OperationFormatter/OperationFormatterMessage/OperationFormatterBodyWriter)
OnWriteStartBody(System.Xml.XmlDictionaryWriter)
OnCreateBufferedCopy(System.Int32)
.ctor(CoreWCF.Dispatcher.OperationFormatter,CoreWCF.Channels.MessageVersion,System.Object[],System.Object,System.Boolean)
ThisLock()
AreParametersBuffered(System.Boolean,CoreWCF.Dispatcher.OperationFormatter)
OnWriteBodyContents(System.Xml.XmlDictionaryWriter)
OnWriteBodyContentsAsync(System.Xml.XmlDictionaryWriter)
OperationFormatter()
.ctor(CoreWCF.Channels.MessageHeaders,System.Collections.Generic.KeyValuePair`2<System.String,System.Object>[],CoreWCF.Channels.BodyWriter)
CreateMessage()
.ctor(CoreWCF.Dispatcher.OperationFormatter,CoreWCF.Channels.MessageVersion,System.String,System.String,System.Boolean,System.String,System.Boolean)
IsMessageVersionSupported(CoreWCF.Channels.MessageVersion)
Name()
Namespace()
MustUnderstand()
Relay()
Actor()
OnWriteStartHeader(System.Xml.XmlDictionaryWriter,CoreWCF.Channels.MessageVersion)
OnWriteHeaderAttributes(System.Xml.XmlDictionaryWriter,CoreWCF.Channels.MessageVersion)
.ctor(CoreWCF.Dispatcher.OperationFormatter,CoreWCF.Channels.MessageVersion,System.String,System.String,System.Boolean,System.String,System.Boolean,System.Xml.XmlElement)
OnWriteHeaderAttributes(System.Xml.XmlDictionaryWriter,CoreWCF.Channels.MessageVersion)
OnWriteHeaderContents(System.Xml.XmlDictionaryWriter,CoreWCF.Channels.MessageVersion)
.ctor(System.String,System.String)
.cctor()
.ctor()
Equals(CoreWCF.Dispatcher.OperationFormatter/QName,CoreWCF.Dispatcher.OperationFormatter/QName)
GetHashCode(CoreWCF.Dispatcher.OperationFormatter/QName)
.ctor()
Add(System.String,System.String,CoreWCF.Description.MessageHeaderDescription)
Get(System.String,System.String)