XmlSerializerOperationBehavior Class

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

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

Namespace:   System.ServiceModel.Description
Assembly:  System.ServiceModel (in System.ServiceModel.dll)

System.Object
  System.ServiceModel.Description.XmlSerializerOperationBehavior

public class XmlSerializerOperationBehavior : IOperationBehavior, 
	IWsdlExportExtension

NameDescription
System_CAPS_pubmethodXmlSerializerOperationBehavior(OperationDescription)

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

System_CAPS_pubmethodXmlSerializerOperationBehavior(OperationDescription, XmlSerializerFormatAttribute)

Initializes a new instance of the XmlSerializerOperationBehavior class.

NameDescription
System_CAPS_pubpropertyXmlSerializerFormatAttribute

Gets the object that holds SOAP use and format options.

NameDescription
System_CAPS_pubmethodEquals(Object)

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethodFinalize()

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)

System_CAPS_pubmethodGetHashCode()

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethodGetType()

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethodGetXmlMappings()

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

System_CAPS_protmethodMemberwiseClone()

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_pubmethodToString()

Returns a string that represents the current object.(Inherited from Object.)

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

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();
}

.NET Framework
Available since 3.0
Silverlight
Available since 4.0
Windows Phone Silverlight
Available since 8.0

Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show: