XmlSerializerOperationBehavior Class

 

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

.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: