#if FEAT_SERVICEMODEL && PLAT_XMLSERIALIZER using System.ServiceModel.Description; namespace ProtoBuf.ServiceModel { /// /// Behavior to swap out DatatContractSerilaizer with the XmlProtoSerializer for a given endpoint. /// /// Add the following to the server and client app.config in the system.serviceModel section: /// /// /// /// /// /// /// /// /// /// /// /// /// /// Configure your endpoints to have a behaviorConfiguration as follows: /// /// /// /// /// /// /// /// /// public class ProtoEndpointBehavior : IEndpointBehavior { #region IEndpointBehavior Members void IEndpointBehavior.AddBindingParameters(ServiceEndpoint endpoint, System.ServiceModel.Channels.BindingParameterCollection bindingParameters) { } void IEndpointBehavior.ApplyClientBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime) { ReplaceDataContractSerializerOperationBehavior(endpoint); } void IEndpointBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.EndpointDispatcher endpointDispatcher) { ReplaceDataContractSerializerOperationBehavior(endpoint); } void IEndpointBehavior.Validate(ServiceEndpoint endpoint) { } private static void ReplaceDataContractSerializerOperationBehavior(ServiceEndpoint serviceEndpoint) { foreach (OperationDescription operationDescription in serviceEndpoint.Contract.Operations) { ReplaceDataContractSerializerOperationBehavior(operationDescription); } } private static void ReplaceDataContractSerializerOperationBehavior(OperationDescription description) { DataContractSerializerOperationBehavior dcsOperationBehavior = description.Behaviors.Find(); if (dcsOperationBehavior != null) { description.Behaviors.Remove(dcsOperationBehavior); ProtoOperationBehavior newBehavior = new ProtoOperationBehavior(description); newBehavior.MaxItemsInObjectGraph = dcsOperationBehavior.MaxItemsInObjectGraph; description.Behaviors.Add(newBehavior); } } #endregion } } #endif