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


Initializes a new instance of the DataContractSerializerOperationBehavior class with the specified operation description.

System_CAPS_pubmethodDataContractSerializerOperationBehavior(OperationDescription, DataContractFormatAttribute)

Initializes a new instance of the DataContractSerializerOperationBehavior class with the specified operation description and data contract format.


Gets the DataContractFormatAttribute associated with the operation.


Gets or sets an implementation of the DataContractResolver that is used to dynamically map types during serialization and deserialization processes.


Gets or sets a surrogate to be used during the serialization and deserialization processes.


Gets or sets a value that specifies whether the data provided by an extension of a type (and therefore not in the data contract) is ignored or not.


Gets or sets the maximum number of items in the object graph to serialize or deserialize.

System_CAPS_pubmethodCreateSerializer(Type, String, String, IList(Of Type))

Creates an instance of a class that inherits from XmlObjectSerializer for serialization and deserialization processes.

System_CAPS_pubmethodCreateSerializer(Type, XmlDictionaryString, XmlDictionaryString, IList(Of Type))

Creates an instance of a class that inherits from XmlObjectSerializer for serialization and deserialization processes with an XmlDictionaryString that contains the namespace.


Determines whether the specified object is equal to the current object.(Inherited from Object.)


Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)


Serves as the default hash function. (Inherited from Object.)


Gets the Type of the current instance.(Inherited from Object.)


Creates a shallow copy of the current Object.(Inherited from Object.)


Returns a string that represents the current object.(Inherited from Object.)

The DataContractSerializerOperationBehavior enables the control of DataContractSerializer options, such as the MaxItemsInObjectGraph and IgnoreExtensionDataObject properties. Some of these properties can be set only 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 behaviors 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 

Universal Windows Platform
Available since 8
.NET Framework
Available since 3.0
Portable Class Library
Supported in: portable .NET platforms

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

Return to top