Rediger

Del via


XmlSerializerOperationBehavior Class

Definition

Controls run-time behavior of the XmlSerializer associated with an operation.

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
Inheritance
XmlSerializerOperationBehavior
Implements

Examples

The following example finds the XmlSerializerOperationBehavior for a specific operation, and sets the Style property of the XmlSerializerFormatAttribute for the serializer.

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

Remarks

The XmlSerializerOperationBehavior enables control of XmlSerializer options, such as the Style property of the XmlSerializerFormatAttribute.

Constructors

XmlSerializerOperationBehavior(OperationDescription, XmlSerializerFormatAttribute)

Initializes a new instance of the XmlSerializerOperationBehavior class.

XmlSerializerOperationBehavior(OperationDescription)

Initializes a new instance of the XmlSerializerOperationBehavior class with a specific operation.

Properties

XmlSerializerFormatAttribute

Gets the object that holds SOAP use and format options.

Methods

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)
GetXmlMappings()

Gets the collection of mappings between XML schema elements and CLR data types.

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 set of parameters to an operation description.

IOperationBehavior.ApplyClientBehavior(OperationDescription, ClientOperation)

Applies a client's behavior to the operation.

IOperationBehavior.ApplyDispatchBehavior(OperationDescription, DispatchOperation)

Applies a dispatch behavior to the operation.

IOperationBehavior.Validate(OperationDescription)

Validates the operation.

IWsdlExportExtension.ExportContract(WsdlExporter, WsdlContractConversionContext)

Exports the operation data as a WSDL document.

IWsdlExportExtension.ExportEndpoint(WsdlExporter, WsdlEndpointConversionContext)

Exports the endpoint data as a WSDL document.

Applies to

See also