DeliveryRequirementsAttribute.TargetContract Property
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets or sets the type to which it applies.
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
The Type to which the attribute applies.
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.
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
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.
Продукт | Версии |
---|---|
.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 |
Обратна връзка за .NET
.NET е проект с отворен код. Изберете връзка, за да предоставите обратна връзка: