Прочетете на английски Редактиране

Споделяне чрез


DeliveryRequirementsAttribute.TargetContract Property

Definition

Gets or sets the type to which it applies.

C#
public Type TargetContract { get; set; }

Property Value

The Type to which the attribute applies.

Examples

The following code example uses the DeliveryRequirementsAttribute attribute to instruct WCF to confirm at runtime that the actual binding does not support queued contracts but does support ordered messages. It also specifies the target contract to which this restriction should be applied.

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

Remarks

A service class can implement any number of service contract interfaces. Use the TargetContract property to validate that endpoints with the TargetContract have bindings that support the requirements. This attribute can be used any number of times on the same class.

Applies to

Продукт Версии
.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