DeliveryRequirementsAttribute.TargetContract Propriedade
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Obtém ou define o tipo a que 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 de Propriedade
A Type que o atributo se aplica.
Exemplos
O exemplo de código seguinte usa o DeliveryRequirementsAttribute atributo para instruir o WCF a confirmar em tempo de execução que a ligação real não suporta contratos em fila, mas suporta mensagens ordenadas. Especifica também o contrato-alvo ao qual esta 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
Observações
Uma classe de serviço pode implementar qualquer número de interfaces de contrato de serviço. Use a TargetContract propriedade para validar que os endpoints têm TargetContract bindings que suportam os requisitos. Este atributo pode ser usado qualquer número de vezes na mesma classe.