DeliveryRequirementsAttribute.TargetContract 屬性

定義

取得或設定套用的類型。

C#
public Type TargetContract { get; set; }

屬性值

屬性要套用的 Type

範例

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

C#
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;
    }
}

備註

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

適用於

產品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1