แก้ไข

แชร์ผ่าน


DataContractSerializerOperationBehavior Class

Definition

Represents the run-time behavior of the DataContractSerializer.

public ref class DataContractSerializerOperationBehavior : System::ServiceModel::Description::IOperationBehavior
public ref class DataContractSerializerOperationBehavior : System::ServiceModel::Description::IOperationBehavior, System::ServiceModel::Description::IWsdlExportExtension
public class DataContractSerializerOperationBehavior : System.ServiceModel.Description.IOperationBehavior
public class DataContractSerializerOperationBehavior : System.ServiceModel.Description.IOperationBehavior, System.ServiceModel.Description.IWsdlExportExtension
type DataContractSerializerOperationBehavior = class
    interface IOperationBehavior
type DataContractSerializerOperationBehavior = class
    interface IOperationBehavior
    interface IWsdlExportExtension
Public Class DataContractSerializerOperationBehavior
Implements IOperationBehavior
Public Class DataContractSerializerOperationBehavior
Implements IOperationBehavior, IWsdlExportExtension
Inheritance
DataContractSerializerOperationBehavior
Implements

Examples

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();
}
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)
        myOperationDescription.Behaviors.Add(serializerBehavior)
    End If
    
    ' Change settings of the behavior.
    serializerBehavior.MaxItemsInObjectGraph = 10000
    serializerBehavior.IgnoreExtensionDataObject = True
    
    sh.Open()
    Console.WriteLine("Listening")
    Console.ReadLine()

End Sub

Remarks

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.

Constructors

DataContractSerializerOperationBehavior(OperationDescription, DataContractFormatAttribute)

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

DataContractSerializerOperationBehavior(OperationDescription)

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

Properties

DataContractFormatAttribute

Gets the DataContractFormatAttribute associated with the operation.

DataContractResolver

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

DataContractSurrogate

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

IgnoreExtensionDataObject

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.

MaxItemsInObjectGraph

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

SerializationSurrogateProvider

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

Methods

CreateSerializer(Type, String, String, IList<Type>)

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

CreateSerializer(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.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

IOperationBehavior.AddBindingParameters(OperationDescription, BindingParameterCollection)

Adds a collection of parameters to the behavior.

IOperationBehavior.ApplyClientBehavior(OperationDescription, ClientOperation)

Attaches a client behavior to the operation.

IOperationBehavior.ApplyDispatchBehavior(OperationDescription, DispatchOperation)

Applies the behavior to the operation.

IOperationBehavior.Validate(OperationDescription)

Validates the operation.

IWsdlExportExtension.ExportContract(WsdlExporter, WsdlContractConversionContext)

Exports the WSDL representation of the operation.

IWsdlExportExtension.ExportEndpoint(WsdlExporter, WsdlEndpointConversionContext)

Exports the endpoint description as a WSDL document.

Applies to

See also