This documentation is archived and is not being maintained.

DataContractSerializerOperationBehavior Class

Represents the run-time behavior of the DataContractSerializer.

Namespace:  System.ServiceModel.Description
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

Public Class DataContractSerializerOperationBehavior _
	Implements IOperationBehavior, IWsdlExportExtension
Dim instance As DataContractSerializerOperationBehavior

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 Sub DataContractBehavior() 
    Dim b As New WSHttpBinding(SecurityMode.Message)
    Dim baseAddress As New Uri("http://localhost:1066/calculator")
    Dim sh As New ServiceHost(GetType(Calculator), baseAddress)
    sh.AddServiceEndpoint(GetType(ICalculator), b, "")

    ' Find the ContractDescription of the operation to find. 
    Dim cd As ContractDescription = sh.Description.Endpoints(0).Contract
    Dim myOperationDescription As OperationDescription = cd.Operations.Find("Add")

    ' Find the serializer behavior. 
    Dim serializerBehavior As DataContractSerializerOperationBehavior = _
    myOperationDescription.Behaviors.Find _
    (Of DataContractSerializerOperationBehavior)()

    ' If the serializer is not found, create one and add it. 
    If serializerBehavior Is Nothing Then
        serializerBehavior = New DataContractSerializerOperationBehavior(myOperationDescription)
    End If 

    ' Change settings of the behavior.
    serializerBehavior.MaxItemsInObjectGraph = 10000
    serializerBehavior.IgnoreExtensionDataObject = True


End Sub


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

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.

.NET Framework

Supported in: 3.5, 3.0