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

属性を適用する 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 が設定されたエンドポイントに、要件をサポートしているバインドがあることを検証します。 この属性は、同じクラスに対して任意の回数だけ使用できます。

適用対象