< Summary - CoreWCF Coverage — PR #1766

Information
Class: CoreWCF.Description.WebHttpBehavior
Assembly: CoreWCF.WebHttp
File(s): /home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/Description/WebHttpBehavior.cs
Line coverage
62%
Covered lines: 313
Uncovered lines: 190
Coverable lines: 503
Total lines: 1139
Line coverage: 62.2%
Branch coverage
55%
Covered branches: 182
Total branches: 330
Branch coverage: 55.1%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
.cctor()100%11100%
.ctor(...)100%11100%
AddBindingParameters(...)100%11100%
ApplyClientBehavior(...)0%880%
ApplyDispatchBehavior(...)65%404063.76%
Validate(...)50%2283.33%
ValidateNoMessageHeadersPresent(...)50%6666.66%
ValidateBinding(...)100%11100%
GetWebMethod(...)83.33%6687.5%
GetWebUriTemplate(...)75%4487.5%
GetDescription(...)0%10100%
IsTypedMessage(...)50%22100%
IsUntypedMessage(...)83.33%121275%
MakeDummyMessageDescription(...)100%11100%
SupportsJsonFormat(...)100%11100%
ValidateIsWebHttpBinding(...)70%101040%
GetBodyStyle(...)75%4487.5%
AddServerErrorHandlers(...)100%22100%
GetOperationSelector(...)100%11100%
GetQueryStringConverter(...)100%11100%
UseBareReplyFormatter(...)50%22100%
GetReplyDispatchFormatter(...)64.28%141465.21%
GetRequestDispatchFormatter(...)75%121292.3%
CloneMessageDescriptionsBeforeActing(...)83.33%66100%
UseBareRequestFormatter(...)50%22100%
CloneParts(...)100%22100%
EnsureNotUntypedMessageNorMessageContract(...)50%101038.46%
EnsureOk(...)75%4450%
HideReplyMessage(...)100%44100%
HideRequestUriTemplateParameters(...)100%11100%
HideRequestUriTemplateParameters(...)87.5%8884.61%
IsBareRequest(...)50%22100%
IsBareResponse(...)50%22100%
TryGetNonMessageParameterType(...)75%202075%
TryGetStreamParameterType(...)69.23%262677.27%
ValidateAtMostOneStreamParameter(...)100%44100%
GetDefaultDispatchFormatter(...)0%880%
CreateDataContractJsonSerializerOperationFormatter(...)0%12120%
GetStreamPart(...)0%10100%
IsValidReturnValue(...)0%220%
GetDefaultXmlAndJsonDispatchFormatter(...)0%220%
GetRequestFormat(...)0%880%
GetResponseFormat(...)87.5%8887.5%
ValidateBodyParameters(...)100%22100%
ValidateBodyStyle(...)100%1010100%
ValidateGETHasNoBody(...)62.5%8837.5%
ValidateContract(...)100%44100%
IsXmlSerializerFaultFormat(...)0%220%
ValidateNoMessageContractWithStream(...)16.66%6633.33%
ValidateNoOperationHasEncodedXmlSerializer(...)33.33%6675%
ValidateNoBareMessageContractWithMultipleParts(...)40%101028.57%
ValidateNoMessageContractHeaders(...)50%2250%
DeserializeReply(...)100%110%
DeserializeRequest(...)100%110%
SerializeReply(...)100%110%
SerializeRequest(...)100%110%

File(s)

/home/runner/work/CoreWCF/CoreWCF/src/CoreWCF.WebHttp/src/CoreWCF/Description/WebHttpBehavior.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System;
 5using System.Collections.Generic;
 6using System.Collections.ObjectModel;
 7using System.ComponentModel;
 8using System.IO;
 9using System.Linq;
 10using System.Reflection;
 11using CoreWCF.Channels;
 12using CoreWCF.Collections.Generic;
 13using CoreWCF.Dispatcher;
 14using CoreWCF.Web;
 15
 16namespace CoreWCF.Description
 17{
 18    public class WebHttpBehavior : IEndpointBehavior
 19    {
 20        internal const string GET = "GET";
 21        internal const string POST = "POST";
 22        internal const string WildcardAction = "*";
 23        internal const string WildcardMethod = "*";
 124        internal static readonly string s_defaultStreamContentType = "application/octet-stream";
 125        internal static readonly string s_defaultCallbackParameterName = "callback";
 26        private WebMessageBodyStyle _defaultBodyStyle;
 27        private WebMessageFormat _defaultOutgoingReplyFormat;
 28        private WebMessageFormat _defaultOutgoingRequestFormat;
 29        private string _contractNamespace;
 30        private readonly UnwrappedTypesXmlSerializerManager _xmlSerializerManager;
 31
 3732        public WebHttpBehavior(IServiceProvider serviceProvider)
 33        {
 3734            _defaultOutgoingRequestFormat = WebMessageFormat.Xml;
 3735            _defaultOutgoingReplyFormat = WebMessageFormat.Xml;
 3736            _defaultBodyStyle = WebMessageBodyStyle.Bare;
 3737            _xmlSerializerManager = new UnwrappedTypesXmlSerializerManager();
 38
 3739            ServiceProvider = serviceProvider;
 3740        }
 41
 042        internal IServiceProvider ServiceProvider { get; }
 43
 44        internal delegate void Effect();
 45
 46        public virtual WebMessageBodyStyle DefaultBodyStyle
 47        {
 64948            get { return _defaultBodyStyle; }
 49            set
 50            {
 051                if (!WebMessageBodyStyleHelper.IsDefined(value))
 52                {
 053                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 54                }
 55
 056                _defaultBodyStyle = value;
 057            }
 58        }
 59
 60        public virtual WebMessageFormat DefaultOutgoingRequestFormat
 61        {
 62            get
 63            {
 064                return _defaultOutgoingRequestFormat;
 65            }
 66            set
 67            {
 068                if (!WebMessageFormatHelper.IsDefined(value))
 69                {
 070                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 71                }
 72
 073                _defaultOutgoingRequestFormat = value;
 074            }
 75        }
 76
 77        public virtual WebMessageFormat DefaultOutgoingResponseFormat
 78        {
 79            get
 80            {
 5581                return _defaultOutgoingReplyFormat;
 82            }
 83            set
 84            {
 085                if (!WebMessageFormatHelper.IsDefined(value))
 86                {
 087                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val
 88                }
 89
 090                _defaultOutgoingReplyFormat = value;
 091            }
 92        }
 93
 14894        public virtual bool HelpEnabled { get; set; }
 95
 3796        public virtual bool AutomaticFormatSelectionEnabled { get; set; }
 97
 3798        public virtual bool FaultExceptionEnabled { get; set; }
 99
 41100        internal Uri HelpUri { get; set; }
 101
 102        public virtual void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
 103        {
 104            // do nothing
 37105        }
 106
 107        public virtual void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
 108        {
 0109            if (endpoint == null)
 110            {
 0111                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(endpoint));
 112            }
 113
 0114            if (clientRuntime == null)
 115            {
 0116                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(clientRuntime));
 117            }
 118
 0119            WebMessageEncodingBindingElement webEncodingBindingElement = endpoint.Binding.CreateBindingElements().Find<W
 0120            if (webEncodingBindingElement != null && webEncodingBindingElement.CrossDomainScriptAccessEnabled)
 121            {
 0122                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.CrossDomainJavasc
 123            }
 124
 0125            _contractNamespace = endpoint.Contract.Namespace;
 0126        }
 127
 128        public virtual void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 129        {
 37130            if (endpoint == null)
 131            {
 0132                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(endpoint));
 133            }
 134
 37135            if (endpointDispatcher == null)
 136            {
 0137                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(endpointDispatcher));
 138            }
 139
 37140            WebMessageEncodingBindingElement webEncodingBindingElement = endpoint.Binding.CreateBindingElements().Find<W
 37141            if (webEncodingBindingElement != null && webEncodingBindingElement.CrossDomainScriptAccessEnabled)
 142            {
 0143                ISecurityCapabilities securityCapabilities = endpoint.Binding.GetProperty<ISecurityCapabilities>(new Bin
 0144                if (securityCapabilities.SupportsClientAuthentication)
 145                {
 0146                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotSupportedException(SR.CrossDomainJa
 147                }
 148            }
 149
 37150            WebHttpServiceModelCompat.ServiceModelAttributeFixup(endpoint);
 151
 37152            if (HelpEnabled)
 153            {
 0154                HelpUri = new UriTemplate(HelpPage.OperationListHelpPageUriTemplate).BindByPosition(endpoint.ListenUri);
 155            }
 156
 37157            _contractNamespace = endpoint.Contract.Namespace;
 158
 159            // endpoint filter
 37160            endpointDispatcher.AddressFilter = new PrefixEndpointAddressMessageFilter(endpoint.Address);
 37161            endpointDispatcher.ContractFilter = new MatchAllMessageFilter();
 162            // operation selector
 37163            endpointDispatcher.DispatchRuntime.OperationSelector = GetOperationSelector(endpoint);
 164            // unhandled operation
 37165            string actionStarOperationName = null;
 400166            foreach (OperationDescription od in endpoint.Contract.Operations)
 167            {
 163168                if (od.Messages[0].Direction == MessageDirection.Input
 163169                    && od.Messages[0].Action == WildcardAction)
 170                {
 0171                    actionStarOperationName = od.Name;
 0172                    break;
 173                }
 174            }
 175
 37176            if (actionStarOperationName != null)
 177            {
 178                // WCF v1 installs any Action="*" op into UnhandledDispatchOperation, but WebHttpBehavior
 179                // doesn't want this, so we 'move' that operation back into normal set of operations
 0180                endpointDispatcher.DispatchRuntime.Operations.Add(
 0181                    endpointDispatcher.DispatchRuntime.UnhandledDispatchOperation);
 182            }
 183
 37184            FormatSelectingMessageInspector formatSelectingMessageInspector = null;
 185            string jsonContentType;
 186            string xmlContentType;
 187
 37188            if (webEncodingBindingElement != null)
 189            {
 37190                XmlFormatMapping xmlFormatMapping = new XmlFormatMapping(webEncodingBindingElement.WriteEncoding, webEnc
 37191                JsonFormatMapping jsonFormatMapping = new JsonFormatMapping(webEncodingBindingElement.WriteEncoding, web
 192
 37193                xmlContentType = xmlFormatMapping.DefaultContentType.ToString();
 37194                jsonContentType = jsonFormatMapping.DefaultContentType.ToString();
 195
 37196                if (AutomaticFormatSelectionEnabled)
 197                {
 0198                    formatSelectingMessageInspector = new FormatSelectingMessageInspector(this, new List<MultiplexingFor
 0199                    endpointDispatcher.DispatchRuntime.MessageInspectors.Add(formatSelectingMessageInspector);
 200                }
 201            }
 202            else
 203            {
 0204                xmlContentType = ContentTypeHelpers.GetContentType(XmlFormatMapping.s_defaultMediaType, TextEncoderDefau
 0205                jsonContentType = JsonMessageEncoderFactory.GetContentType(null);
 206            }
 207
 208            // always install UnhandledDispatchOperation (WebHttpDispatchOperationSelector may choose not to use it)
 37209            endpointDispatcher.DispatchRuntime.UnhandledDispatchOperation = new DispatchOperation(endpointDispatcher.Dis
 37210            endpointDispatcher.DispatchRuntime.UnhandledDispatchOperation.DeserializeRequest = false;
 37211            endpointDispatcher.DispatchRuntime.UnhandledDispatchOperation.SerializeReply = false;
 37212            endpointDispatcher.DispatchRuntime.UnhandledDispatchOperation.Invoker = new HttpUnhandledOperationInvoker { 
 213
 214            // install formatters and parameter inspectors
 400215            foreach (OperationDescription od in endpoint.Contract.Operations)
 216            {
 163217                DispatchOperation dop = null;
 163218                if (endpointDispatcher.DispatchRuntime.Operations.Contains(od.Name))
 219                {
 163220                    dop = endpointDispatcher.DispatchRuntime.Operations[od.Name];
 221                }
 0222                else if (endpointDispatcher.DispatchRuntime.UnhandledDispatchOperation.Name == od.Name)
 223                {
 0224                    dop = endpointDispatcher.DispatchRuntime.UnhandledDispatchOperation;
 225                }
 226
 163227                if (dop != null)
 228                {
 163229                    IDispatchMessageFormatter requestDispatch = GetRequestDispatchFormatter(od, endpoint);
 163230                    IDispatchMessageFormatter replyDispatch = GetReplyDispatchFormatter(od, endpoint);
 231
 232
 163233                    if (replyDispatch is MultiplexingDispatchMessageFormatter replyDispatchAsMultiplexing)
 234                    {
 235                        // here we are adding all default content types, despite the fact that
 236                        // some of the formatters in MultiplexingDispatchMessageFormatter might not be present
 237                        // i.e. the JSON formatter
 238
 160239                        replyDispatchAsMultiplexing.DefaultContentTypes.Add(WebMessageFormat.Xml, xmlContentType);
 160240                        replyDispatchAsMultiplexing.DefaultContentTypes.Add(WebMessageFormat.Json, jsonContentType);
 241
 160242                        if (formatSelectingMessageInspector != null)
 243                        {
 0244                            formatSelectingMessageInspector.RegisterOperation(od.Name, replyDispatchAsMultiplexing);
 245                        }
 246                    }
 247
 163248                    dop.Formatter = new CompositeDispatchFormatter(requestDispatch, replyDispatch);
 163249                    dop.FaultFormatter = new WebFaultFormatter(dop.FaultFormatter);
 163250                    dop.DeserializeRequest = (requestDispatch != null);
 163251                    dop.SerializeReply = od.Messages.Count > 1 && (replyDispatch != null);
 252                }
 253            }
 254
 37255            if (HelpEnabled)
 256            {
 0257                HelpPage helpPage = new HelpPage();
 0258                DispatchOperation dispatchOperation = new DispatchOperation(endpointDispatcher.DispatchRuntime, HelpOper
 0259                {
 0260                    DeserializeRequest = false,
 0261                    SerializeReply = false,
 0262                    Invoker = new HelpOperationInvoker(helpPage),
 0263                };
 0264                endpointDispatcher.DispatchRuntime.Operations.Add(dispatchOperation);
 265            }
 266
 37267            AddServerErrorHandlers(endpoint, endpointDispatcher);
 37268        }
 269
 270        public virtual void Validate(ServiceEndpoint endpoint)
 271        {
 37272            if (endpoint == null)
 273            {
 0274                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(endpoint));
 275            }
 276
 37277            ValidateNoMessageHeadersPresent(endpoint);
 37278            ValidateBinding(endpoint);
 37279            ValidateContract(endpoint);
 37280        }
 281
 282        private void ValidateNoMessageHeadersPresent(ServiceEndpoint endpoint)
 283        {
 37284            if (endpoint == null || endpoint.Address == null)
 285            {
 0286                return;
 287            }
 288
 37289            EndpointAddress address = endpoint.Address;
 37290            if (address.Headers.Count > 0)
 291            {
 0292                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.Web
 293            }
 37294        }
 295
 296        protected virtual void ValidateBinding(ServiceEndpoint endpoint)
 297        {
 37298            ValidateIsWebHttpBinding(endpoint, GetType().ToString());
 37299        }
 300
 301        internal static string GetWebMethod(OperationDescription od)
 302        {
 529303            WebGetAttribute wga = ((KeyedByTypeCollection<IOperationBehavior>)od.OperationBehaviors).Find<WebGetAttribut
 529304            WebInvokeAttribute wia = ((KeyedByTypeCollection<IOperationBehavior>)od.OperationBehaviors).Find<WebInvokeAt
 529305            EnsureOk(wga, wia, od);
 529306            if (wga != null)
 307            {
 454308                return GET;
 309            }
 75310            else if (wia != null)
 311            {
 75312                return wia.Method ?? POST;
 313            }
 314            else
 315            {
 0316                return POST;
 317            }
 318        }
 319
 320        internal static string GetWebUriTemplate(OperationDescription od)
 321        {
 322            // return exactly what is on the attribute
 529323            WebGetAttribute wga = ((KeyedByTypeCollection<IOperationBehavior>)od.OperationBehaviors).Find<WebGetAttribut
 529324            WebInvokeAttribute wia = ((KeyedByTypeCollection<IOperationBehavior>)od.OperationBehaviors).Find<WebInvokeAt
 529325            EnsureOk(wga, wia, od);
 529326            if (wga != null)
 327            {
 454328                return wga.UriTemplate;
 329            }
 75330            else if (wia != null)
 331            {
 75332                return wia.UriTemplate;
 333            }
 334            else
 335            {
 0336                return null;
 337            }
 338        }
 339
 340        internal static string GetDescription(OperationDescription od)
 341        {
 0342            object[] attributes = null;
 0343            if (od.SyncMethod != null)
 344            {
 0345                attributes = od.SyncMethod.GetCustomAttributes(typeof(DescriptionAttribute), true);
 346            }
 0347            else if (od.BeginMethod != null)
 348            {
 0349                attributes = od.BeginMethod.GetCustomAttributes(typeof(DescriptionAttribute), true);
 350            }
 0351            else if (od.TaskMethod != null)
 352            {
 0353                attributes = od.TaskMethod.GetCustomAttributes(typeof(DescriptionAttribute), true);
 354            }
 355
 0356            if (attributes != null && attributes.Length > 0)
 357            {
 0358                return ((DescriptionAttribute)attributes[0]).Description;
 359            }
 360            else
 361            {
 0362                return string.Empty;
 363            }
 364        }
 365
 2113366        internal static bool IsTypedMessage(MessageDescription message) => message != null && message.MessageType != nul
 367
 368        internal static bool IsUntypedMessage(MessageDescription message)
 369        {
 1759370            if (message == null)
 371            {
 0372                return false;
 373            }
 374
 1759375            return (message.Body.ReturnValue != null && message.Body.Parts.Count == 0 && message.Body.ReturnValue.Type =
 1759376                (message.Body.ReturnValue == null && message.Body.Parts.Count == 1 && message.Body.Parts[0].Type == type
 377        }
 378
 379        internal static MessageDescription MakeDummyMessageDescription(MessageDirection direction)
 380        {
 163381            MessageDescription messageDescription = new MessageDescription("urn:dummyAction", direction);
 163382            return messageDescription;
 383        }
 384
 385        internal static bool SupportsJsonFormat(OperationDescription od)
 386        {
 387            // if the type is XmlSerializable, then we cannot create a json serializer for it
 218388            DataContractSerializerOperationBehavior dcsob = ((KeyedByTypeCollection<IOperationBehavior>)od.OperationBeha
 218389            return (dcsob != null);
 390        }
 391
 392        internal static void ValidateIsWebHttpBinding(ServiceEndpoint serviceEndpoint, string behaviorName)
 393        {
 37394            Binding binding = serviceEndpoint.Binding;
 37395            if (binding.Scheme != "http" && binding.Scheme != "https")
 396            {
 0397                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
 0398                    SR.Format(SR.WCFBindingCannotBeUsedWithUriOperationSelectorBehaviorBadScheme,
 0399                    serviceEndpoint.Contract.Name, behaviorName)));
 400            }
 401
 37402            if (binding.MessageVersion != MessageVersion.None)
 403            {
 0404                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
 0405                    SR.Format(SR.WCFBindingCannotBeUsedWithUriOperationSelectorBehaviorBadMessageVersion,
 0406                    serviceEndpoint.Address.Uri.AbsoluteUri, behaviorName)));
 407            }
 408
 37409            TransportBindingElement transportBindingElement = binding.CreateBindingElements().Find<TransportBindingEleme
 37410            if (transportBindingElement != null && !transportBindingElement.ManualAddressing)
 411            {
 0412                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
 0413                    SR.Format(SR.ManualAddressingCannotBeFalseWithTransportBindingElement,
 0414                    serviceEndpoint.Address.Uri.AbsoluteUri, behaviorName, transportBindingElement.GetType().Name)));
 415            }
 37416        }
 417
 418        internal WebMessageBodyStyle GetBodyStyle(OperationDescription od)
 419        {
 649420            WebGetAttribute wga = ((KeyedByTypeCollection<IOperationBehavior>)od.OperationBehaviors).Find<WebGetAttribut
 649421            WebInvokeAttribute wia = ((KeyedByTypeCollection<IOperationBehavior>)od.OperationBehaviors).Find<WebInvokeAt
 649422            EnsureOk(wga, wia, od);
 649423            if (wga != null)
 424            {
 552425                return wga.GetBodyStyleOrDefault(DefaultBodyStyle);
 426            }
 97427            else if (wia != null)
 428            {
 97429                return wia.GetBodyStyleOrDefault(DefaultBodyStyle);
 430            }
 431            else
 432            {
 0433                return DefaultBodyStyle;
 434            }
 435        }
 436
 437        protected virtual void AddServerErrorHandlers(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
 438        {
 37439            if (!FaultExceptionEnabled)
 440            {
 37441                WebErrorHandler errorHandler = new WebErrorHandler(this, endpoint.Contract, endpointDispatcher.DispatchR
 37442                endpointDispatcher.DispatchRuntime.ChannelDispatcher.ErrorHandlers.Add(errorHandler);
 443            }
 37444        }
 445
 37446        protected virtual WebHttpDispatchOperationSelector GetOperationSelector(ServiceEndpoint endpoint) => new WebHttp
 447
 326448        protected virtual QueryStringConverter GetQueryStringConverter(OperationDescription operationDescription) => new
 449
 450        internal virtual bool UseBareReplyFormatter(WebMessageBodyStyle style, OperationDescription operationDescription
 451        {
 160452            parameterType = null;
 453
 160454            return IsBareResponse(style) && TryGetNonMessageParameterType(operationDescription.Messages[1], operationDes
 455        }
 456
 457        protected virtual IDispatchMessageFormatter GetReplyDispatchFormatter(OperationDescription operationDescription,
 458        {
 163459            if (operationDescription.Messages.Count < 2)
 460            {
 0461                return null;
 462            }
 463
 163464            ValidateBodyParameters(operationDescription, false);
 163465            WebMessageFormat responseFormat = GetResponseFormat(operationDescription);
 466
 467            //  Determine if we should add a json formatter; If the ResponseFormat is json, we always add the json forma
 468            //  operation is XmlSerializerFormat because the formatter constructor throws the exception: "json not valid
 163469            bool useJson = (responseFormat == WebMessageFormat.Json || SupportsJsonFormat(operationDescription));
 470
 471            IDispatchMessageFormatter innerFormatter;
 472
 163473            if (TryGetStreamParameterType(operationDescription.Messages[1], operationDescription, false, out Type type))
 474            {
 3475                innerFormatter = new ContentTypeSettingDispatchMessageFormatter(s_defaultStreamContentType, new HttpStre
 476            }
 160477            else if (IsUntypedMessage(operationDescription.Messages[1]))
 478            {
 0479                innerFormatter = new MessagePassthroughFormatter();
 480            }
 481            else
 482            {
 160483                WebMessageBodyStyle style = GetBodyStyle(operationDescription);
 160484                Dictionary<WebMessageFormat, IDispatchMessageFormatter> formatters = new Dictionary<WebMessageFormat, ID
 485
 160486                if (UseBareReplyFormatter(style, operationDescription, responseFormat, out Type parameterType))
 487                {
 160488                    formatters.Add(WebMessageFormat.Xml, SingleBodyParameterMessageFormatter.CreateDispatchFormatter(ope
 160489                    if (useJson)
 490                    {
 491                        //formatters.Add(WebMessageFormat.Json, SingleBodyParameterMessageFormatter.CreateDispatchFormat
 160492                        formatters.Add(WebMessageFormat.Json, SingleBodyParameterMessageFormatter.CreateDispatchFormatte
 493                    }
 494                }
 495                else
 496                {
 0497                    MessageDescription temp = operationDescription.Messages[0];
 0498                    operationDescription.Messages[0] = MakeDummyMessageDescription(MessageDirection.Input);
 0499                    formatters.Add(WebMessageFormat.Xml, GetDefaultDispatchFormatter(operationDescription, false, !IsBar
 0500                    if (useJson)
 501                    {
 0502                        formatters.Add(WebMessageFormat.Json, GetDefaultDispatchFormatter(operationDescription, true, !I
 503                    }
 0504                    operationDescription.Messages[0] = temp;
 505                }
 160506                innerFormatter = new MultiplexingDispatchMessageFormatter(formatters, responseFormat);
 507            }
 508
 163509            return innerFormatter;
 510        }
 511
 512        protected virtual IDispatchMessageFormatter GetRequestDispatchFormatter(OperationDescription operationDescriptio
 513        {
 163514            IDispatchMessageFormatter result = null;
 515            // get some validation errors by creating "throwAway" formatter
 163516            UriTemplateDispatchFormatter throwAway = new UriTemplateDispatchFormatter(operationDescription, null, GetQue
 163517            int numUriVariables = throwAway._pathMapping.Count + throwAway._queryMapping.Count;
 163518            HideReplyMessage(operationDescription, delegate ()
 163519            {
 163520                WebMessageBodyStyle style = GetBodyStyle(operationDescription);
 163521                Effect doBodyFormatter = delegate ()
 163522                {
 163523                    if (numUriVariables != 0)
 163524                    {
 40525                        EnsureNotUntypedMessageNorMessageContract(operationDescription);
 163526                    }
 163527
 163528                    // get body formatter
 163529                    ValidateBodyParameters(operationDescription, true);
 163530                    if (TryGetStreamParameterType(operationDescription.Messages[0], operationDescription, true, out Type
 163531                    {
 3532                        result = new HttpStreamFormatter(operationDescription);
 163533                    }
 163534                    else
 163535                    {
 160536                        if (UseBareRequestFormatter(style, operationDescription, out Type parameterType))
 163537                        {
 163538                            // TODO: Can I remove this?
 163539                            //result = SingleBodyParameterMessageFormatter.CreateXmlAndJsonDispatchFormatter(operationDe
 160540                            result = SingleBodyParameterMessageFormatter.CreateXmlAndJsonDispatchFormatter(operationDesc
 163541                        }
 163542                        else
 163543                        {
 0544                            result = GetDefaultXmlAndJsonDispatchFormatter(operationDescription, !IsBareRequest(style));
 163545                        }
 163546                    }
 163547                };
 163548
 163549                if (numUriVariables == 0)
 163550                {
 123551                    if (IsUntypedMessage(operationDescription.Messages[0]))
 163552                    {
 0553                        ValidateBodyParameters(operationDescription, true);
 0554                        result = new MessagePassthroughFormatter();
 163555                    }
 123556                    else if (IsTypedMessage(operationDescription.Messages[0]))
 163557                    {
 0558                        ValidateBodyParameters(operationDescription, true);
 0559                        result = GetDefaultXmlAndJsonDispatchFormatter(operationDescription, !IsBareRequest(style));
 163560                    }
 163561                    else
 163562                    {
 123563                        doBodyFormatter();
 163564                    }
 163565                }
 163566                else
 163567                {
 40568                    HideRequestUriTemplateParameters(operationDescription, throwAway, delegate ()
 40569                    {
 40570                        CloneMessageDescriptionsBeforeActing(operationDescription, delegate ()
 40571                        {
 40572                            doBodyFormatter();
 80573                        });
 80574                    });
 163575                }
 163576
 163577                result = new UriTemplateDispatchFormatter(operationDescription, result, GetQueryStringConverter(operatio
 326578            });
 579
 163580            return result;
 581        }
 582
 583        private static void CloneMessageDescriptionsBeforeActing(OperationDescription operationDescription, Effect effec
 584        {
 40585            MessageDescription originalRequest = operationDescription.Messages[0];
 40586            bool thereIsAReply = operationDescription.Messages.Count > 1;
 40587            MessageDescription originalReply = thereIsAReply ? operationDescription.Messages[1] : null;
 40588            operationDescription.Messages[0] = originalRequest.Clone();
 40589            if (thereIsAReply)
 590            {
 40591                operationDescription.Messages[1] = originalReply.Clone();
 592            }
 593
 40594            effect();
 40595            operationDescription.Messages[0] = originalRequest;
 40596            if (thereIsAReply)
 597            {
 40598                operationDescription.Messages[1] = originalReply;
 599            }
 40600        }
 601
 602        internal virtual bool UseBareRequestFormatter(WebMessageBodyStyle style, OperationDescription operationDescripti
 603        {
 160604            parameterType = null;
 605
 160606            return IsBareRequest(style) && TryGetNonMessageParameterType(operationDescription.Messages[0], operationDesc
 607        }
 608
 609        private static Collection<MessagePartDescription> CloneParts(MessageDescription md)
 610        {
 80611            MessagePartDescriptionCollection bodyParameters = md.Body.Parts;
 80612            Collection<MessagePartDescription> bodyParametersClone = new Collection<MessagePartDescription>();
 352613            for (int i = 0; i < bodyParameters.Count; ++i)
 614            {
 96615                MessagePartDescription copy = bodyParameters[i].Clone();
 96616                bodyParametersClone.Add(copy);
 617            }
 618
 80619            return bodyParametersClone;
 620        }
 621
 622        private static void EnsureNotUntypedMessageNorMessageContract(OperationDescription operationDescription)
 623        {
 624            // Called when there are UriTemplate parameters.  UT does not compose with Message
 625            // or MessageContract because the SOAP and REST programming models must be uniform here.
 40626            bool isUnadornedWebGet = false;
 40627            if (GetWebMethod(operationDescription) == GET && GetWebUriTemplate(operationDescription) == null)
 628            {
 0629                isUnadornedWebGet = true;
 630            }
 631
 40632            if (IsTypedMessage(operationDescription.Messages[0]))
 633            {
 0634                if (isUnadornedWebGet)
 635                {
 636                    // WebGet will give you UriTemplate parameters by default.
 637                    // We need a special error message for this case to prevent confusion.
 0638                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
 0639                        SR.Format(SR.GETCannotHaveMCParameter, operationDescription.Name, operationDescription.Declaring
 640                }
 641                else
 642                {
 0643                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(
 0644                        SR.UTParamsDoNotComposeWithMessageContract, operationDescription.Name, operationDescription.Decl
 645                }
 646            }
 647
 40648            if (IsUntypedMessage(operationDescription.Messages[0]))
 649            {
 0650                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(
 0651                    SR.UTParamsDoNotComposeWithMessage, operationDescription.Name, operationDescription.DeclaringContrac
 652            }
 40653        }
 654
 655        private static void EnsureOk(WebGetAttribute wga, WebInvokeAttribute wia, OperationDescription od)
 656        {
 1870657            if (wga != null && wia != null)
 658            {
 0659                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
 0660                    SR.Format(SR.MultipleWebAttributes, od.Name, od.DeclaringContract.Name)));
 661            }
 1870662        }
 663
 664        private static void HideReplyMessage(OperationDescription operationDescription, Effect effect)
 665        {
 163666            MessageDescription temp = null;
 163667            if (operationDescription.Messages.Count > 1)
 668            {
 163669                temp = operationDescription.Messages[1];
 163670                operationDescription.Messages[1] = MakeDummyMessageDescription(MessageDirection.Output);
 671            }
 672
 163673            effect();
 163674            if (operationDescription.Messages.Count > 1)
 675            {
 163676                operationDescription.Messages[1] = temp;
 677            }
 163678        }
 679
 680        internal static void HideRequestUriTemplateParameters(OperationDescription operationDescription, UriTemplateDisp
 681        {
 40682            HideRequestUriTemplateParameters(operationDescription, throwAway._pathMapping, throwAway._queryMapping, effe
 40683        }
 684
 685        private static void HideRequestUriTemplateParameters(OperationDescription operationDescription, Dictionary<int, 
 686        {
 687            // mutate description to hide UriTemplate parameters
 40688            Collection<MessagePartDescription> originalParts = CloneParts(operationDescription.Messages[0]);
 40689            Collection<MessagePartDescription> parts = CloneParts(operationDescription.Messages[0]);
 40690            operationDescription.Messages[0].Body.Parts.Clear();
 40691            int newIndex = 0;
 176692            for (int i = 0; i < parts.Count; ++i)
 693            {
 48694                if (!pathMapping.ContainsKey(i) && !queryMapping.ContainsKey(i))
 695                {
 0696                    operationDescription.Messages[0].Body.Parts.Add(parts[i]);
 0697                    parts[i].Index = newIndex++;
 698                }
 699            }
 700
 40701            effect();
 702            // unmutate description
 40703            operationDescription.Messages[0].Body.Parts.Clear();
 176704            for (int i = 0; i < originalParts.Count; ++i)
 705            {
 48706                operationDescription.Messages[0].Body.Parts.Add(originalParts[i]);
 707            }
 40708        }
 709
 323710        private static bool IsBareRequest(WebMessageBodyStyle style) => style == WebMessageBodyStyle.Bare || style == We
 711
 323712        private static bool IsBareResponse(WebMessageBodyStyle style) => style == WebMessageBodyStyle.Bare || style == W
 713
 714        internal static bool TryGetNonMessageParameterType(MessageDescription message, OperationDescription declaringOpe
 715        {
 646716            type = null;
 646717            if (message == null)
 718            {
 0719                return true;
 720            }
 721
 646722            if (IsTypedMessage(message) || IsUntypedMessage(message))
 723            {
 0724                return false;
 725            }
 726
 646727            if (isRequest)
 728            {
 323729                if (message.Body.Parts.Count > 1)
 730                {
 0731                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR
 732                }
 733
 323734                if (message.Body.Parts.Count == 1 && message.Body.Parts[0].Type != typeof(void))
 735                {
 31736                    type = message.Body.Parts[0].Type;
 737                }
 738
 323739                return true;
 740            }
 741            else
 742            {
 323743                if (message.Body.Parts.Count > 0)
 744                {
 0745                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR
 746                }
 747
 323748                if (message.Body.ReturnValue != null && message.Body.ReturnValue.Type != typeof(void))
 749                {
 247750                    type = message.Body.ReturnValue.Type;
 751                }
 752
 323753                return true;
 754            }
 755        }
 756
 757        private static bool TryGetStreamParameterType(MessageDescription message, OperationDescription declaringOperatio
 758        {
 652759            type = null;
 652760            if (message == null || IsTypedMessage(message) || IsUntypedMessage(message))
 761            {
 0762                return false;
 763            }
 764
 652765            if (isRequest)
 766            {
 326767                bool hasStream = false;
 708768                for (int i = 0; i < message.Body.Parts.Count; ++i)
 769                {
 34770                    if (typeof(Stream) == message.Body.Parts[i].Type)
 771                    {
 6772                        type = message.Body.Parts[i].Type;
 6773                        hasStream = true;
 6774                        break;
 775                    }
 776
 777                }
 778
 326779                if (hasStream && message.Body.Parts.Count > 1)
 780                {
 0781                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.AtMostO
 782                }
 783
 326784                return hasStream;
 785            }
 786            else
 787            {
 788                // validate that the stream is not an out or ref param
 652789                for (int i = 0; i < message.Body.Parts.Count; ++i)
 790                {
 0791                    if (typeof(Stream) == message.Body.Parts[i].Type)
 792                    {
 0793                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.NoO
 794                    }
 795                }
 796
 326797                if (message.Body.ReturnValue != null && typeof(Stream) == message.Body.ReturnValue.Type)
 798                {
 799                    // validate that there are no out or ref params
 6800                    if (message.Body.Parts.Count > 0)
 801                    {
 0802                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.Format(SR.NoO
 803                    }
 6804                    type = message.Body.ReturnValue.Type;
 6805                    return true;
 806                }
 807
 808                else
 809                {
 320810                    return false;
 811                }
 812            }
 813        }
 814
 815        private static void ValidateAtMostOneStreamParameter(OperationDescription operation, bool request)
 816        {
 817            Type dummy;
 326818            if (request)
 819            {
 163820                TryGetStreamParameterType(operation.Messages[0], operation, true, out dummy);
 821            }
 822            else
 823            {
 163824                if (operation.Messages.Count > 1)
 825                {
 163826                    TryGetStreamParameterType(operation.Messages[1], operation, false, out dummy);
 827                }
 828            }
 163829        }
 830
 831        private IDispatchMessageFormatter GetDefaultDispatchFormatter(OperationDescription od, bool useJson, bool isWrap
 832        {
 0833            DataContractSerializerOperationBehavior dcsob = ((KeyedByTypeCollection<IOperationBehavior>)od.OperationBeha
 0834            if (useJson)
 835            {
 0836                if (dcsob == null)
 837                {
 0838                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR
 839                }
 0840                return CreateDataContractJsonSerializerOperationFormatter(od, dcsob, isWrapped);
 841            }
 842            else
 843            {
 0844                EndpointDispatcher dummyED = new EndpointDispatcher(new EndpointAddress("http://localhost/"), "name", ""
 0845                DispatchRuntime dispatchRuntime = dummyED.DispatchRuntime;
 0846                DispatchOperation dop = new DispatchOperation(dispatchRuntime, "dummyDispatch", "urn:dummy");
 0847                dop.Formatter = null;
 848
 0849                if (dcsob != null)
 850                {
 0851                    (dcsob as IOperationBehavior).ApplyDispatchBehavior(od, dop);
 0852                    return dop.Formatter;
 853                }
 854
 0855                XmlSerializerOperationBehavior xsob = ((KeyedByTypeCollection<IOperationBehavior>)od.OperationBehaviors)
 0856                if (xsob != null)
 857                {
 0858                    xsob = new XmlSerializerOperationBehavior(od, xsob.XmlSerializerFormatAttribute, _contractNamespace)
 0859                    (xsob as IOperationBehavior).ApplyDispatchBehavior(od, dop);
 0860                    return dop.Formatter;
 861                }
 862            }
 863
 0864            return null;
 865        }
 866
 867        internal virtual DataContractJsonSerializerOperationFormatter CreateDataContractJsonSerializerOperationFormatter
 868        {
 869            //return new DataContractJsonSerializerOperationFormatter(od, dcsob.MaxItemsInObjectGraph, dcsob.IgnoreExten
 870
 0871            OperationDescription clonedOperation = new OperationDescription(od.Name, od.DeclaringContract);
 0872            foreach (MessageDescription message in od.Messages)
 873            {
 0874                MessageDescription clonedMessage = message.Clone();
 0875                if (IsValidReturnValue(clonedMessage.Body.ReturnValue))
 876                {
 0877                    if (clonedMessage.Body.Parts.Count == 0)
 878                    {
 0879                        if (clonedMessage.Body.ReturnValue.Type == typeof(Stream))
 880                        {
 0881                            clonedMessage.Body.WrapperName = JsonGlobals.RootString;
 0882                            clonedMessage.Body.WrapperNamespace = string.Empty;
 883                        }
 884                    }
 885                }
 886                else
 887                {
 0888                    if (clonedMessage.Body.Parts.Count == 1)
 889                    {
 0890                        if (clonedMessage.Body.Parts[0].Type == typeof(Stream))
 891                        {
 0892                            clonedMessage.Body.WrapperName = JsonGlobals.RootString;
 0893                            clonedMessage.Body.WrapperNamespace = string.Empty;
 894                        }
 895                    }
 896                }
 897
 0898                clonedOperation.Messages.Add(clonedMessage);
 899            }
 900
 0901            return new DataContractJsonSerializerOperationFormatter(clonedOperation, dcsob.MaxItemsInObjectGraph, dcsob.
 902        }
 903
 904        private static MessagePartDescription GetStreamPart(MessageDescription messageDescription)
 905        {
 0906            if (IsValidReturnValue(messageDescription.Body.ReturnValue))
 907            {
 0908                if (messageDescription.Body.Parts.Count == 0)
 909                {
 0910                    if (messageDescription.Body.ReturnValue.Type == typeof(Stream))
 911                    {
 0912                        return messageDescription.Body.ReturnValue;
 913                    }
 914                }
 915            }
 916            else
 917            {
 0918                if (messageDescription.Body.Parts.Count == 1)
 919                {
 0920                    if (messageDescription.Body.Parts[0].Type == typeof(Stream))
 921                    {
 0922                        return messageDescription.Body.Parts[0];
 923                    }
 924                }
 925            }
 926
 0927            return null;
 928        }
 929
 0930        private static bool IsValidReturnValue(MessagePartDescription returnValue) => (returnValue != null) && (returnVa
 931
 932        // TODO: Can I remove this?
 933        //IClientMessageFormatter GetDefaultXmlAndJsonClientFormatter(OperationDescription od, bool isWrapped)
 934        //{
 935        //    IClientMessageFormatter xmlFormatter = GetDefaultClientFormatter(od, false, isWrapped);
 936        //    if (!SupportsJsonFormat(od))
 937        //    {
 938        //        return xmlFormatter;
 939        //    }
 940        //    IClientMessageFormatter jsonFormatter = GetDefaultClientFormatter(od, true, isWrapped);
 941        //    Dictionary<WebContentFormat, IClientMessageFormatter> map = new Dictionary<WebContentFormat, IClientMessag
 942        //    map.Add(WebContentFormat.Xml, xmlFormatter);
 943        //    map.Add(WebContentFormat.Json, jsonFormatter);
 944        //    // In case there is no format property, the default formatter to use is XML
 945        //    return new DemultiplexingClientMessageFormatter(map, xmlFormatter);
 946        //}
 947
 948        private IDispatchMessageFormatter GetDefaultXmlAndJsonDispatchFormatter(OperationDescription od, bool isWrapped)
 949        {
 0950            IDispatchMessageFormatter xmlFormatter = GetDefaultDispatchFormatter(od, false, isWrapped);
 0951            if (!SupportsJsonFormat(od))
 952            {
 0953                return xmlFormatter;
 954            }
 955
 0956            IDispatchMessageFormatter jsonFormatter = GetDefaultDispatchFormatter(od, true, isWrapped);
 0957            Dictionary<WebContentFormat, IDispatchMessageFormatter> map = new Dictionary<WebContentFormat, IDispatchMess
 0958            map.Add(WebContentFormat.Xml, xmlFormatter);
 0959            map.Add(WebContentFormat.Json, jsonFormatter);
 0960            return new DemultiplexingDispatchMessageFormatter(map, xmlFormatter);
 961        }
 962
 963        internal WebMessageFormat GetRequestFormat(OperationDescription od)
 964        {
 0965            WebGetAttribute wga = ((KeyedByTypeCollection<IOperationBehavior>)od.OperationBehaviors).Find<WebGetAttribut
 0966            WebInvokeAttribute wia = ((KeyedByTypeCollection<IOperationBehavior>)od.OperationBehaviors).Find<WebInvokeAt
 0967            EnsureOk(wga, wia, od);
 0968            if (wga != null)
 969            {
 0970                return wga.IsRequestFormatSetExplicitly ? wga.RequestFormat : this.DefaultOutgoingRequestFormat;
 971            }
 0972            else if (wia != null)
 973            {
 0974                return wia.IsRequestFormatSetExplicitly ? wia.RequestFormat : this.DefaultOutgoingRequestFormat;
 975            }
 976            else
 977            {
 0978                return DefaultOutgoingRequestFormat;
 979            }
 980        }
 981
 982        internal WebMessageFormat GetResponseFormat(OperationDescription od)
 983        {
 163984            WebGetAttribute wga = ((KeyedByTypeCollection<IOperationBehavior>)od.OperationBehaviors).Find<WebGetAttribut
 163985            WebInvokeAttribute wia = ((KeyedByTypeCollection<IOperationBehavior>)od.OperationBehaviors).Find<WebInvokeAt
 163986            EnsureOk(wga, wia, od);
 163987            if (wga != null)
 988            {
 138989                return wga.IsResponseFormatSetExplicitly ? wga.ResponseFormat : this.DefaultOutgoingResponseFormat;
 990            }
 25991            else if (wia != null)
 992            {
 25993                return wia.IsResponseFormatSetExplicitly ? wia.ResponseFormat : this.DefaultOutgoingResponseFormat;
 994            }
 995            else
 996            {
 0997                return DefaultOutgoingResponseFormat;
 998            }
 999        }
 1000
 1001        private void ValidateBodyParameters(OperationDescription operation, bool request)
 1002        {
 3261003            string method = GetWebMethod(operation);
 3261004            if (request)
 1005            {
 1631006                ValidateGETHasNoBody(operation, method);
 1007            }
 1008
 1009            // validate that if bare is chosen for request/response, then at most 1 parameter is possible
 3261010            ValidateBodyStyle(operation, request);
 1011            // validate if the request or response body is a stream, no other body parameters
 1012            // can be specified
 3261013            ValidateAtMostOneStreamParameter(operation, request);
 3261014        }
 1015
 1016        private void ValidateBodyStyle(OperationDescription operation, bool request)
 1017        {
 3261018            WebMessageBodyStyle style = GetBodyStyle(operation);
 1019            Type dummy;
 3261020            if (request && IsBareRequest(style))
 1021            {
 1631022                TryGetNonMessageParameterType(operation.Messages[0], operation, true, out dummy);
 1023            }
 1024
 3261025            if (!request && operation.Messages.Count > 1 && IsBareResponse(style))
 1026            {
 1631027                TryGetNonMessageParameterType(operation.Messages[1], operation, false, out dummy);
 1028            }
 3261029        }
 1030
 1031        private void ValidateGETHasNoBody(OperationDescription operation, string method)
 1032        {
 1631033            if (method == GET)
 1034            {
 1381035                if (!IsUntypedMessage(operation.Messages[0]) && operation.Messages[0].Body.Parts.Count != 0)
 1036                {
 01037                    if (!IsTypedMessage(operation.Messages[0]))
 1038                    {
 01039                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
 01040                            SR.Format(SR.GETCannotHaveBody, operation.Name, operation.DeclaringContract.Name, operation.
 1041                    }
 1042                    else
 1043                    {
 01044                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
 01045                            SR.Format(SR.GETCannotHaveMCParameter, operation.Name, operation.DeclaringContract.Name, ope
 1046                    }
 1047                }
 1048            }
 1631049        }
 1050
 1051        private void ValidateContract(ServiceEndpoint endpoint)
 1052        {
 4001053            foreach (OperationDescription od in endpoint.Contract.Operations)
 1054            {
 1631055                ValidateNoOperationHasEncodedXmlSerializer(od);
 1631056                ValidateNoMessageContractHeaders(od.Messages[0], od.Name, endpoint.Contract.Name);
 1631057                ValidateNoBareMessageContractWithMultipleParts(od.Messages[0], od.Name, endpoint.Contract.Name);
 1631058                ValidateNoMessageContractWithStream(od.Messages[0], od.Name, endpoint.Contract.Name);
 1631059                if (od.Messages.Count > 1)
 1060                {
 1631061                    ValidateNoMessageContractHeaders(od.Messages[1], od.Name, endpoint.Contract.Name);
 1631062                    ValidateNoBareMessageContractWithMultipleParts(od.Messages[1], od.Name, endpoint.Contract.Name);
 1631063                    ValidateNoMessageContractWithStream(od.Messages[1], od.Name, endpoint.Contract.Name);
 1064                }
 1065            }
 371066        }
 1067
 1068        internal static bool IsXmlSerializerFaultFormat(OperationDescription operationDescription)
 1069        {
 01070            XmlSerializerOperationBehavior xsob = ((KeyedByTypeCollection<IOperationBehavior>)operationDescription.Opera
 1071
 01072            return (xsob != null && xsob.XmlSerializerFormatAttribute.SupportFaults);
 1073        }
 1074
 1075        private void ValidateNoMessageContractWithStream(MessageDescription md, string opName, string contractName)
 1076        {
 3261077            if (IsTypedMessage(md))
 1078            {
 01079                foreach (MessagePartDescription description in md.Body.Parts)
 1080                {
 01081                    if (description.Type == typeof(Stream))
 1082                    {
 01083                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
 01084                            new InvalidOperationException(SR.Format(SR.StreamBodyMemberNotSupported, GetType().ToString(
 1085                    }
 1086                }
 1087            }
 3261088        }
 1089
 1090        private void ValidateNoOperationHasEncodedXmlSerializer(OperationDescription od)
 1091        {
 1631092            XmlSerializerOperationBehavior xsob = ((KeyedByTypeCollection<IOperationBehavior>)od.OperationBehaviors).Fin
 1631093            if (xsob != null && (xsob.XmlSerializerFormatAttribute.Style == OperationFormatStyle.Rpc || xsob.XmlSerializ
 1094            {
 01095                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR.Rpc
 1096            }
 1631097        }
 1098
 1099        private void ValidateNoBareMessageContractWithMultipleParts(MessageDescription md, string opName, string contrac
 1100        {
 3261101            if (IsTypedMessage(md) && md.Body.WrapperName == null)
 1102            {
 01103                if (md.Body.Parts.Count > 1)
 1104                {
 01105                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
 01106                        SR.Format(SR.InvalidMessageContractWithoutWrapperName, opName, contractName, md.MessageType)));
 1107                }
 1108
 01109                if (md.Body.Parts.Count == 1 && md.Body.Parts[0].Multiple)
 1110                {
 01111                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.Format(SR
 1112                }
 1113            }
 3261114        }
 1115
 1116        private void ValidateNoMessageContractHeaders(MessageDescription md, string opName, string contractName)
 1117        {
 3261118            if (md.Headers.Count != 0)
 1119            {
 01120                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
 01121                    SR.Format(SR.InvalidMethodWithSOAPHeaders, opName, contractName)));
 1122            }
 3261123        }
 1124
 1125        internal class MessagePassthroughFormatter : IClientMessageFormatter, IDispatchMessageFormatter
 1126        {
 01127            public object DeserializeReply(Message message, object[] parameters) => message;
 1128
 1129            public void DeserializeRequest(Message message, object[] parameters)
 1130            {
 01131                parameters[0] = message;
 01132            }
 1133
 01134            public Message SerializeReply(MessageVersion messageVersion, object[] parameters, object result) => result a
 1135
 01136            public Message SerializeRequest(MessageVersion messageVersion, object[] parameters) => parameters[0] as Mess
 1137        }
 1138    }
 1139}

Methods/Properties

.cctor()
.ctor(System.IServiceProvider)
ServiceProvider()
DefaultBodyStyle()
DefaultBodyStyle(CoreWCF.Web.WebMessageBodyStyle)
DefaultOutgoingRequestFormat()
DefaultOutgoingRequestFormat(CoreWCF.Web.WebMessageFormat)
DefaultOutgoingResponseFormat()
DefaultOutgoingResponseFormat(CoreWCF.Web.WebMessageFormat)
HelpEnabled()
AutomaticFormatSelectionEnabled()
FaultExceptionEnabled()
HelpUri()
AddBindingParameters(CoreWCF.Description.ServiceEndpoint,CoreWCF.Channels.BindingParameterCollection)
ApplyClientBehavior(CoreWCF.Description.ServiceEndpoint,CoreWCF.Dispatcher.ClientRuntime)
ApplyDispatchBehavior(CoreWCF.Description.ServiceEndpoint,CoreWCF.Dispatcher.EndpointDispatcher)
Validate(CoreWCF.Description.ServiceEndpoint)
ValidateNoMessageHeadersPresent(CoreWCF.Description.ServiceEndpoint)
ValidateBinding(CoreWCF.Description.ServiceEndpoint)
GetWebMethod(CoreWCF.Description.OperationDescription)
GetWebUriTemplate(CoreWCF.Description.OperationDescription)
GetDescription(CoreWCF.Description.OperationDescription)
IsTypedMessage(CoreWCF.Description.MessageDescription)
IsUntypedMessage(CoreWCF.Description.MessageDescription)
MakeDummyMessageDescription(CoreWCF.Description.MessageDirection)
SupportsJsonFormat(CoreWCF.Description.OperationDescription)
ValidateIsWebHttpBinding(CoreWCF.Description.ServiceEndpoint,System.String)
GetBodyStyle(CoreWCF.Description.OperationDescription)
AddServerErrorHandlers(CoreWCF.Description.ServiceEndpoint,CoreWCF.Dispatcher.EndpointDispatcher)
GetOperationSelector(CoreWCF.Description.ServiceEndpoint)
GetQueryStringConverter(CoreWCF.Description.OperationDescription)
UseBareReplyFormatter(CoreWCF.Web.WebMessageBodyStyle,CoreWCF.Description.OperationDescription,CoreWCF.Web.WebMessageFormat,System.Type&)
GetReplyDispatchFormatter(CoreWCF.Description.OperationDescription,CoreWCF.Description.ServiceEndpoint)
GetRequestDispatchFormatter(CoreWCF.Description.OperationDescription,CoreWCF.Description.ServiceEndpoint)
CloneMessageDescriptionsBeforeActing(CoreWCF.Description.OperationDescription,CoreWCF.Description.WebHttpBehavior/Effect)
UseBareRequestFormatter(CoreWCF.Web.WebMessageBodyStyle,CoreWCF.Description.OperationDescription,System.Type&)
CloneParts(CoreWCF.Description.MessageDescription)
EnsureNotUntypedMessageNorMessageContract(CoreWCF.Description.OperationDescription)
EnsureOk(CoreWCF.Web.WebGetAttribute,CoreWCF.Web.WebInvokeAttribute,CoreWCF.Description.OperationDescription)
HideReplyMessage(CoreWCF.Description.OperationDescription,CoreWCF.Description.WebHttpBehavior/Effect)
HideRequestUriTemplateParameters(CoreWCF.Description.OperationDescription,CoreWCF.Dispatcher.UriTemplateDispatchFormatter,CoreWCF.Description.WebHttpBehavior/Effect)
HideRequestUriTemplateParameters(CoreWCF.Description.OperationDescription,System.Collections.Generic.Dictionary`2<System.Int32,System.String>,System.Collections.Generic.Dictionary`2<System.Int32,System.Collections.Generic.KeyValuePair`2<System.String,System.Type>>,CoreWCF.Description.WebHttpBehavior/Effect)
IsBareRequest(CoreWCF.Web.WebMessageBodyStyle)
IsBareResponse(CoreWCF.Web.WebMessageBodyStyle)
TryGetNonMessageParameterType(CoreWCF.Description.MessageDescription,CoreWCF.Description.OperationDescription,System.Boolean,System.Type&)
TryGetStreamParameterType(CoreWCF.Description.MessageDescription,CoreWCF.Description.OperationDescription,System.Boolean,System.Type&)
ValidateAtMostOneStreamParameter(CoreWCF.Description.OperationDescription,System.Boolean)
GetDefaultDispatchFormatter(CoreWCF.Description.OperationDescription,System.Boolean,System.Boolean)
CreateDataContractJsonSerializerOperationFormatter(CoreWCF.Description.OperationDescription,CoreWCF.Description.DataContractSerializerOperationBehavior,System.Boolean)
GetStreamPart(CoreWCF.Description.MessageDescription)
IsValidReturnValue(CoreWCF.Description.MessagePartDescription)
GetDefaultXmlAndJsonDispatchFormatter(CoreWCF.Description.OperationDescription,System.Boolean)
GetRequestFormat(CoreWCF.Description.OperationDescription)
GetResponseFormat(CoreWCF.Description.OperationDescription)
ValidateBodyParameters(CoreWCF.Description.OperationDescription,System.Boolean)
ValidateBodyStyle(CoreWCF.Description.OperationDescription,System.Boolean)
ValidateGETHasNoBody(CoreWCF.Description.OperationDescription,System.String)
ValidateContract(CoreWCF.Description.ServiceEndpoint)
IsXmlSerializerFaultFormat(CoreWCF.Description.OperationDescription)
ValidateNoMessageContractWithStream(CoreWCF.Description.MessageDescription,System.String,System.String)
ValidateNoOperationHasEncodedXmlSerializer(CoreWCF.Description.OperationDescription)
ValidateNoBareMessageContractWithMultipleParts(CoreWCF.Description.MessageDescription,System.String,System.String)
ValidateNoMessageContractHeaders(CoreWCF.Description.MessageDescription,System.String,System.String)
DeserializeReply(CoreWCF.Channels.Message,System.Object[])
DeserializeRequest(CoreWCF.Channels.Message,System.Object[])
SerializeReply(CoreWCF.Channels.MessageVersion,System.Object[],System.Object)
SerializeRequest(CoreWCF.Channels.MessageVersion,System.Object[])