DeliveryRequirementsAttribute.TargetContract Propriedade

Definição

Obtém ou define o tipo ao qual ele se aplica.

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

Valor da propriedade

Type

Ao Type qual o atributo se aplica.

Exemplos

O exemplo de código a seguir usa o atributo para instruir o DeliveryRequirementsAttribute WCF a confirmar em runtime que a associação real não dá suporte a contratos enfileirados, mas dá suporte a mensagens ordenadas. Ele também especifica o contrato de destino ao qual essa restrição deve ser aplicada.

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

Comentários

Uma classe de serviço pode implementar qualquer número de interfaces de contrato de serviço. Use a TargetContract propriedade para validar os pontos de extremidade com as TargetContract associações que dão suporte aos requisitos. Esse atributo pode ser usado várias vezes na mesma classe.

Aplica-se a