This documentation is archived and is not being maintained.
XmlSerializerOperationBehavior Class
Visual Studio 2008
Controls run-time behavior of the XmlSerializer associated with an operation.
Assembly: System.ServiceModel (in System.ServiceModel.dll)
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(); }
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: