DeliveryRequirementsAttribute.TargetContract 屬性

定義

取得或設定套用的類型。

public:
 property Type ^ TargetContract { Type ^ get(); void set(Type ^ value); };
public Type TargetContract { get; set; }
member this.TargetContract : Type with get, set
Public Property TargetContract As Type

屬性值

屬性要套用的 Type

範例

下列程式碼範例會使用 DeliveryRequirementsAttribute 屬性指示 WCF 在執行時間確認實際系結不支援佇列合約,但支援已排序的訊息。 它也指定此限制套用的目標合約。

using System;
using System.ServiceModel;

[ServiceContract]
interface ICalculatorService
{
    [OperationBehavior(TransactionAutoComplete = true)]
    int Add(int a, int b);

    [OperationContract]
    int Subtract(int a, int b);
}

[DeliveryRequirementsAttribute(
  QueuedDeliveryRequirements = QueuedDeliveryRequirementsMode.NotAllowed,
  RequireOrderedDelivery = true,
  TargetContract= typeof(ICalculatorService)
)]
class CalculatorService : ICalculatorService
{
    public int Add(int a, int b)
    {
        Console.WriteLine("Add called.");
        return a + b;
    }

    public int Subtract(int a, int b)
    {
        Console.WriteLine("Subtract called.");
        return a - b;
    }

    public int Multiply(int a, int b)
    {
        return a * b;
    }
}
Imports System.ServiceModel

<ServiceContract()> _
Public Interface ICalculatorService

    <OperationBehavior(TransactionAutoComplete:=True)> _
    Function Add(ByVal a As Integer, ByVal b As Integer) As Integer

    <OperationContract()> _
    Function Subtract(ByVal a As Integer, ByVal b As Integer) As Integer
End Interface

<DeliveryRequirementsAttribute( _
    QueuedDeliveryRequirements:=QueuedDeliveryRequirementsMode.NotAllowed, _
    RequireOrderedDelivery:=True, _
    TargetContract:=GetType(ICalculatorService) _
)> _
Class CalculatorService

    Public Function add(ByVal a As Integer, ByVal b As Integer) As Integer
        Console.WriteLine("Add called")
        Return a + b
    End Function

    Public Function Subtract(ByVal a As Integer, ByVal b As Integer) As Integer
        Console.WriteLine("Subtract called.")
        Return a - b
    End Function

    Public Function Multiply(ByVal a As Integer, ByVal b As Integer) As Integer
        Return a * b
    End Function
End Class

備註

服務類別可實作任意數目的服務合約介面。 使用 TargetContract 屬性驗證具有 TargetContract 的端點擁有支援要求的繫結程序。 此屬性可對相同類別使用,次數不限。

適用於