XmlSerializerOperationBehavior 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
控制与操作相关联的 XmlSerializer 的运行时行为。
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
- 继承
-
XmlSerializerOperationBehavior
- 实现
示例
下面的示例查找特定操作的 XmlSerializerOperationBehavior,并为序列化程序设置 Style 的 XmlSerializerFormatAttribute 属性。
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
注解
XmlSerializerOperationBehavior 支持控制 XmlSerializer 选项,如 Style 的 XmlSerializerFormatAttribute 属性。
构造函数
属性
XmlSerializerFormatAttribute |
获取保存 SOAP 使用和格式选项的对象。 |
方法
Equals(Object) |
确定指定对象是否等于当前对象。 (继承自 Object) |
GetHashCode() |
作为默认哈希函数。 (继承自 Object) |
GetType() |
获取当前实例的 Type。 (继承自 Object) |
GetXmlMappings() |
获取 XML 架构元素和 CLR 数据类型之间的映射集合。 |
MemberwiseClone() |
创建当前 Object 的浅表副本。 (继承自 Object) |
ToString() |
返回表示当前对象的字符串。 (继承自 Object) |