Export (0) Print
Expand All

DataContractSerializerOperationBehavior Class

Represents the run-time behavior of the DataContractSerializer.

System.Object
  System.ServiceModel.Description.DataContractSerializerOperationBehavior

Namespace:  System.ServiceModel.Description
Assemblies:   System.ServiceModel (in System.ServiceModel.dll)
  System.ServiceModel.Primitives (in System.ServiceModel.Primitives.dll)

public class DataContractSerializerOperationBehavior : IOperationBehavior, 
	IWsdlExportExtension

The DataContractSerializerOperationBehavior type exposes the following members.

  NameDescription
Public methodSupported in .NET for Windows Store appsDataContractSerializerOperationBehavior(OperationDescription)Initializes a new instance of the DataContractSerializerOperationBehavior class with the specified operation description.
Public methodSupported in .NET for Windows Store appsDataContractSerializerOperationBehavior(OperationDescription, DataContractFormatAttribute)Initializes a new instance of the DataContractSerializerOperationBehavior class with the specified operation description and data contract format.
Top

  NameDescription
Public propertySupported in .NET for Windows Store appsDataContractFormatAttributeGets the DataContractFormatAttribute associated with the operation.
Public propertySupported in .NET for Windows Store appsDataContractResolverGets or sets an implementation of the DataContractResolver that is used to dynamically map types during serialization and deserialization processes.
Public propertyDataContractSurrogateGets or sets a surrogate to be used during the serialization and deserialization processes.
Public propertyIgnoreExtensionDataObjectGets 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.
Public propertySupported in .NET for Windows Store appsMaxItemsInObjectGraphGets or sets the maximum number of items in the object graph to serialize or deserialize.
Top

  NameDescription
Public methodSupported in .NET for Windows Store appsCreateSerializer(Type, String, String, IList<Type>)Creates an instance of a class that inherits from XmlObjectSerializer for serialization and deserialization processes.
Public methodSupported in .NET for Windows Store appsCreateSerializer(Type, XmlDictionaryString, XmlDictionaryString, IList<Type>)Creates an instance of a class that inherits from XmlObjectSerializer for serialization and deserialization processes with an XmlDictionaryString that contains the namespace.
Public methodSupported in .NET for Windows Store appsEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported in .NET for Windows Store appsFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported in .NET for Windows Store appsGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodSupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Protected methodSupported in .NET for Windows Store appsMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported in .NET for Windows Store appsToStringReturns a string that represents the current object. (Inherited from Object.)
Top

  NameDescription
Explicit interface implemetationPrivate methodSupported in .NET for Windows Store appsIOperationBehavior.AddBindingParametersAdds a collection of parameters to the behavior.
Explicit interface implemetationPrivate methodSupported in .NET for Windows Store appsIOperationBehavior.ApplyClientBehaviorAttaches a client behavior to the operation.
Explicit interface implemetationPrivate methodSupported in .NET for Windows Store appsIOperationBehavior.ApplyDispatchBehaviorApplies the behavior to the operation.
Explicit interface implemetationPrivate methodSupported in .NET for Windows Store appsIOperationBehavior.ValidateValidates the operation.
Explicit interface implemetationPrivate methodIWsdlExportExtension.ExportContractExports the WSDL representation of the operation.
Explicit interface implemetationPrivate methodIWsdlExportExtension.ExportEndpointExports the endpoint description as a WSDL document.
Top

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 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();
}

.NET Framework

Supported in: 4.5.3, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

.NET for Windows Store apps

Supported in: Windows 8

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

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