Leer en inglés Editar

Compartir a través de


XmlSerializerOperationBehavior Class

Definition

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

public class XmlSerializerOperationBehavior : System.ServiceModel.Description.IOperationBehavior
public class XmlSerializerOperationBehavior : System.ServiceModel.Description.IOperationBehavior, System.ServiceModel.Description.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();
}

Remarks

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

Constructors

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

Applies to

Producto Versiones
.NET 8 (package-provided), 9 (package-provided)
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7 (package-provided), 4.7, 4.7.1 (package-provided), 4.7.1, 4.7.2 (package-provided), 4.7.2, 4.8 (package-provided), 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

See also