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 使用和格式选项的对象。

方法

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 文档形式导出终结点数据。

适用于

另请参阅