DataContractSerializerOperationBehavior 類別

定義

表示 DataContractSerializer的執行階段行為。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
繼承
DataContractSerializerOperationBehavior
實作

範例

下列範例會在行為集合中尋找作業的 DataContractSerializerOperationBehavior,並重設 MaxItemsInObjectGraphIgnoreExtensionDataObject 屬性。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 

備註

DataContractSerializerOperationBehavior 會啟用 DataContractSerializer 選項的控制項,例如 MaxItemsInObjectGraphIgnoreExtensionDataObject 屬性。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. 此時您可以使用 DataContractSerializer 方法取代 CreateSerializerIn that case, the DataContractSerializer can be replaced using the CreateSerializer method. 如需資料合約的詳細資訊,請參閱 使用資料合約For more information about data contracts, see Using Data Contracts.

如需使用 DataContractSerializerOperationBehavior 取代屬性所傳回之的詳細資訊 IDataContractSurrogate DataContractSurrogate ,請參閱 資料合約代理程式。For more information about using the DataContractSerializerOperationBehavior to replace the IDataContractSurrogate returned by the DataContractSurrogate property, see Data Contract Surrogates.

建構函式

DataContractSerializerOperationBehavior(OperationDescription)

使用指定的作業描述,初始化 DataContractSerializerOperationBehavior 類別的新執行個體。Initializes a new instance of the DataContractSerializerOperationBehavior class with the specified operation description.

DataContractSerializerOperationBehavior(OperationDescription, DataContractFormatAttribute)

使用指定的作業描述和資料合約格式,初始化 DataContractSerializerOperationBehavior 類別的新執行個體。Initializes a new instance of the DataContractSerializerOperationBehavior class with the specified operation description and data contract format.

屬性

DataContractFormatAttribute

取得與作業關聯的 DataContractFormatAttributeGets the DataContractFormatAttribute associated with the operation.

DataContractResolver

取得或設定進行序列化及還原序列化程序時,用於動態對應型別的 DataContractResolver 實作。Gets or sets an implementation of the DataContractResolver that is used to dynamically map types during serialization and deserialization processes.

DataContractSurrogate

取得或設定進行序列化和還原序列化程序時要使用的 Surrogate。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

取得或設定進行序列化與還原序列化程序時要使用的 Surrogate 提供者。Gets or sets a surrogate provider to be used during the serialization and deserialization processes.

方法

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

為序列化和還原序列化程序建立繼承自 XmlObjectSerializer 之類別的執行個體。Creates an instance of a class that inherits from XmlObjectSerializer for serialization and deserialization processes.

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

使用包含命名空間的 XmlObjectSerializer,為序列化和還原序列化程序建立繼承自 XmlDictionaryString 之類別的執行個體。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.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)

明確介面實作

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)

匯出作業的 WSDL 表示法。Exports the WSDL representation of the operation.

IWsdlExportExtension.ExportEndpoint(WsdlExporter, WsdlEndpointConversionContext)

將端點描述匯出為 WSDL 文件。Exports the endpoint description as a WSDL document.

適用於

另請參閱