In the previous post we discussed possible scenarios and methods for configuring reliable message delivery in WCF. Let's look further into this great WCF feature.
Delivery assurances can have a large impact on the way your code processes incoming messages. Especially, ordering can be of importance if your code relies on ordered message delivery. Since configuration can be changed by any WCF service administrator there is a knob in WCF which lets you demand the appropriate binding. The knob is in a form of a declarative attribute, called DeliveryRequirementsAttribute.
Here's how it's used:
[DeliveryRequirements(RequireOrderedDelivery = true,
QueuedDeliveryRequirements =
QueuedDeliveryRequirementsMode.Required)]
interface IServiceContract
{
int Operation(int a, int b);
}
DeliveryRequirementsAttribute can be set on any service interface or service class implementation. It has three properties:
- QueuedDeliveryRequirements which has three possible values, Allowed, NotAllowed and Required. Setting NotAllowed or Required makes the binding either demand or prevent WS-RM usage. Setting Allowed does not make any requirements.
- RequireOrderedDelivery demands a binding that supports and has ordered delivery turned on.
- TargetContract property is applicable only when the attibute is applied to a class definition. Since WCF service interfaces can be implemented by multiple classes, one can specify a specific interface for which the queued delivery requirements are defined.
The specified contract interface would demand a WS-RM capable binding and thus prevent service administrators to turn reliable delivery off.
In case where an administrator would turn reliable delivery (or ordering, in this case) off, the service host would throw an exception while trying to host the service.
So, DeliveryRequirementsAttribute guards developers from wrongdoings of service administrators. It should set QueuedDeliveryRequirements = QueuedDeliveryRequirementsMode.Required or RequireOrderedDelivery = true, when there are objective reasons to demand guaranteed and/or ordered delivery of messages.
HedaWhece - petek, 15. november 2024
<a href=https://fastpriligy.top/>buy priligy online</a> Younger and more aggressive teachers and professors have replaced those bad guys in the penis enlargement growth system past and left