DeliveryRequirementsAttribute.TargetContract Proprietà

Definizione

Ottiene o imposta il tipo al quale si applica l'attributo.

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

Valore della proprietà

Type

Type al quale si applica l'attributo.

Esempio

L'esempio di codice seguente usa l'attributo per indicare a WCF di confermare in fase di esecuzione che l'associazione DeliveryRequirementsAttribute effettiva non supporta i contratti in coda, ma supporta i messaggi ordinati. Viene inoltre specificato il contratto di destinazione al quale deve essere applicata tale restrizione.

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

Commenti

Una classe di servizio può implementare qualsiasi numero di interfacce del contratto di servizio. Utilizzare la proprietà TargetContract per convalidare che gli endpoints con TargetContract dispongono di associazioni che supportano i requisiti. Questo attributo può essere utilizzato qualsiasi numero di volte sulla stessa classe.

Si applica a