共用方式為


XmlSerializerOperationBehavior 類別

定義

控制與作業相關聯的 XmlSerializer 執行階段行為。

public ref class XmlSerializerOperationBehavior : System::ServiceModel::Description::IOperationBehavior
public ref class XmlSerializerOperationBehavior : System::ServiceModel::Description::IOperationBehavior, System::ServiceModel::Description::IWsdlExportExtension
public class XmlSerializerOperationBehavior : System.ServiceModel.Description.IOperationBehavior
public class XmlSerializerOperationBehavior : System.ServiceModel.Description.IOperationBehavior, System.ServiceModel.Description.IWsdlExportExtension
type XmlSerializerOperationBehavior = class
    interface IOperationBehavior
type XmlSerializerOperationBehavior = class
    interface IOperationBehavior
    interface IWsdlExportExtension
Public Class XmlSerializerOperationBehavior
Implements IOperationBehavior
Public Class XmlSerializerOperationBehavior
Implements IOperationBehavior, IWsdlExportExtension
繼承
XmlSerializerOperationBehavior
實作

範例

下列範例會針對特定作業尋找 XmlSerializerOperationBehavior,並針對序列化程式設定 StyleXmlSerializerFormatAttribute 屬性。

private void Run()
{
    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.
    XmlSerializerOperationBehavior  serializerBehavior =
        myOperationDescription.Behaviors.
           Find<XmlSerializerOperationBehavior>();

    // If the serializer is not found, create one and add it.
    if (serializerBehavior == null)
    {
        serializerBehavior = new XmlSerializerOperationBehavior(myOperationDescription);
        myOperationDescription.Behaviors.Add(serializerBehavior);
    }

    // Change style of the serialize attribute.
    serializerBehavior.XmlSerializerFormatAttribute.Style = OperationFormatStyle.Document;

    sh.Open();
    Console.WriteLine("Listening");
    Console.ReadLine();
    sh.Close();
}
Private Sub Run()
    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 XmlSerializerOperationBehavior = myOperationDescription.Behaviors. Find(Of XmlSerializerOperationBehavior)()

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

    ' Change style of the serialize attribute.
    serializerBehavior.XmlSerializerFormatAttribute.Style = OperationFormatStyle.Document

    sh.Open()
    Console.WriteLine("Listening")
    Console.ReadLine()
    sh.Close()
End Sub

備註

XmlSerializerOperationBehavior 會啟用 XmlSerializer 選項的控制權,例如 StyleXmlSerializerFormatAttribute 屬性。

建構函式

XmlSerializerOperationBehavior(OperationDescription)

使用特定的作業,初始化 XmlSerializerOperationBehavior 類別的新執行個體。

XmlSerializerOperationBehavior(OperationDescription, XmlSerializerFormatAttribute)

初始化 XmlSerializerOperationBehavior 類別的新執行個體。

屬性

XmlSerializerFormatAttribute

取得會保留 SOAP use 和格式選項的物件。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
GetXmlMappings()

取得 XML 結構描述項目和 CLR 資料型別之間的對應集合。

MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

明確介面實作

IOperationBehavior.AddBindingParameters(OperationDescription, BindingParameterCollection)

將一組參數加入至作業描述。

IOperationBehavior.ApplyClientBehavior(OperationDescription, ClientOperation)

將用戶端的行為套用到作業。

IOperationBehavior.ApplyDispatchBehavior(OperationDescription, DispatchOperation)

將分派行為套用到作業。

IOperationBehavior.Validate(OperationDescription)

驗證作業。

IWsdlExportExtension.ExportContract(WsdlExporter, WsdlContractConversionContext)

將作業資料匯出為 WSDL 文件。

IWsdlExportExtension.ExportEndpoint(WsdlExporter, WsdlEndpointConversionContext)

將端點資料匯出為 WSDL 文件。

適用於

另請參閱