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 use 和格式選項的物件。 |
方法
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
GetXmlMappings() |
取得 XML 結構描述項目和 CLR 資料型別之間的對應集合。 |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |