| | | 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 | | |
| | | 4 | | using System.Collections.ObjectModel; |
| | | 5 | | using CoreWCF.Channels; |
| | | 6 | | using CoreWCF.Description; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Dispatcher |
| | | 9 | | { |
| | | 10 | | internal class DataContractSerializerServiceBehavior : IServiceBehavior, IEndpointBehavior |
| | | 11 | | { |
| | 0 | 12 | | internal DataContractSerializerServiceBehavior(bool ignoreExtensionDataObject, int maxItemsInObjectGraph) |
| | | 13 | | { |
| | 0 | 14 | | IgnoreExtensionDataObject = ignoreExtensionDataObject; |
| | 0 | 15 | | MaxItemsInObjectGraph = maxItemsInObjectGraph; |
| | 0 | 16 | | } |
| | | 17 | | |
| | 0 | 18 | | public bool IgnoreExtensionDataObject { get; set; } |
| | | 19 | | |
| | 0 | 20 | | public int MaxItemsInObjectGraph { get; set; } |
| | | 21 | | |
| | | 22 | | void IServiceBehavior.Validate(ServiceDescription description, ServiceHostBase serviceHostBase) |
| | | 23 | | { |
| | 0 | 24 | | } |
| | | 25 | | |
| | | 26 | | void IServiceBehavior.AddBindingParameters(ServiceDescription description, ServiceHostBase serviceHostBase, Coll |
| | | 27 | | { |
| | 0 | 28 | | } |
| | | 29 | | |
| | | 30 | | void IServiceBehavior.ApplyDispatchBehavior(ServiceDescription description, ServiceHostBase serviceHostBase) |
| | | 31 | | { |
| | 0 | 32 | | ApplySerializationSettings(description, IgnoreExtensionDataObject, MaxItemsInObjectGraph); |
| | 0 | 33 | | } |
| | | 34 | | |
| | | 35 | | void IEndpointBehavior.Validate(ServiceEndpoint serviceEndpoint) |
| | | 36 | | { |
| | 0 | 37 | | } |
| | | 38 | | |
| | | 39 | | void IEndpointBehavior.AddBindingParameters(ServiceEndpoint serviceEndpoint, BindingParameterCollection paramete |
| | | 40 | | { |
| | 0 | 41 | | } |
| | | 42 | | |
| | | 43 | | void IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientRuntime clientRuntime) |
| | | 44 | | { |
| | 0 | 45 | | ApplySerializationSettings(serviceEndpoint, IgnoreExtensionDataObject, MaxItemsInObjectGraph); |
| | 0 | 46 | | } |
| | | 47 | | |
| | | 48 | | void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint serviceEndpoint, EndpointDispatcher endpointDispatc |
| | | 49 | | { |
| | 0 | 50 | | ApplySerializationSettings(serviceEndpoint, IgnoreExtensionDataObject, MaxItemsInObjectGraph); |
| | 0 | 51 | | } |
| | | 52 | | |
| | | 53 | | internal static void ApplySerializationSettings(ServiceDescription description, bool ignoreExtensionDataObject, |
| | | 54 | | { |
| | 2434 | 55 | | foreach (ServiceEndpoint endpoint in description.Endpoints) |
| | | 56 | | { |
| | 641 | 57 | | if (!endpoint.InternalIsSystemEndpoint(description)) |
| | | 58 | | { |
| | 641 | 59 | | ApplySerializationSettings(endpoint, ignoreExtensionDataObject, maxItemsInObjectGraph); |
| | | 60 | | } |
| | | 61 | | } |
| | 576 | 62 | | } |
| | | 63 | | |
| | | 64 | | internal static void ApplySerializationSettings(ServiceEndpoint endpoint, bool ignoreExtensionDataObject, int ma |
| | | 65 | | { |
| | 7338 | 66 | | foreach (OperationDescription operation in endpoint.Contract.Operations) |
| | | 67 | | { |
| | 24582 | 68 | | foreach (IOperationBehavior ob in operation.Behaviors) |
| | | 69 | | { |
| | 9263 | 70 | | if (ob is DataContractSerializerOperationBehavior behavior) |
| | | 71 | | { |
| | 2978 | 72 | | if (!behavior.IgnoreExtensionDataObjectSetExplicit) |
| | | 73 | | { |
| | 2978 | 74 | | behavior.ignoreExtensionDataObject = ignoreExtensionDataObject; |
| | | 75 | | } |
| | 2978 | 76 | | if (!behavior.MaxItemsInObjectGraphSetExplicit) |
| | | 77 | | { |
| | 2978 | 78 | | behavior.maxItemsInObjectGraph = maxItemsInObjectGraph; |
| | | 79 | | } |
| | | 80 | | } |
| | | 81 | | } |
| | | 82 | | } |
| | 641 | 83 | | } |
| | | 84 | | } |
| | | 85 | | } |