DataContractSerializerOperationBehavior Class
Represents the run-time behavior of the DataContractSerializer.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
The DataContractSerializerOperationBehavior enables control of DataContractSerializer options, such as the MaxItemsInObjectGraph and IgnoreExtensionDataObject properties. Some properties can only be set using the constructor of the class. In that case, the DataContractSerializer can be replaced using the CreateSerializer method. For more information about data contracts, see Using Data Contracts.
For more information about using the DataContractSerializerOperationBehavior to replace the IDataContractSurrogate returned by the DataContractSurrogate property, see Data Contract Surrogates.
The following example finds the DataContractSerializerOperationBehavior in the collection of behavior for an operation and resets the MaxItemsInObjectGraph and IgnoreExtensionDataObject properties.
private void DataContractBehavior() { WSHttpBinding b = new WSHttpBinding(SecurityMode.Message); Uri baseAddress = new Uri("http://localhost:1066/calculator"); ServiceHost sh = new ServiceHost(typeof(Calculator), baseAddress); sh.AddServiceEndpoint(typeof(ICalculator), b, ""); // Find the ContractDescription of the operation to find. ContractDescription cd = sh.Description.Endpoints[0].Contract; OperationDescription myOperationDescription = cd.Operations.Find("Add"); // Find the serializer behavior. DataContractSerializerOperationBehavior serializerBehavior = myOperationDescription.Behaviors. Find<DataContractSerializerOperationBehavior>(); // If the serializer is not found, create one and add it. if (serializerBehavior == null) { serializerBehavior = new DataContractSerializerOperationBehavior(myOperationDescription); myOperationDescription.Behaviors.Add(serializerBehavior); } // Change the settings of the behavior. serializerBehavior.MaxItemsInObjectGraph = 10000; serializerBehavior.IgnoreExtensionDataObject = true; sh.Open(); Console.WriteLine("Listening"); Console.ReadLine(); }
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.