WCF custom channel assured delivery

Assured Delivery guarantees that a service request or reply is actioned and not lost.

A request message is received and any reply message is sent under a local transaction sync point, which can be rolled back in the case of runtime failure. Examples of these failures are: An unhandled exception thrown by the service, failure to dispatch the message to the service, or failure to deliver the reply message.

AssuredDelivery is the assured delivery attribute which can be specified on a service contract to guarantee that any request messages received by a service, and any reply message sent from a service, is not lost in the event of a runtime failure.

To ensure that messages are also preserved in the event of system failure or power outage, messages must be sent as persistent. To use persistent messages the client application must have this option specified on its endpoint URI.

Distributed transactions are not supported, and the scope of the transaction does not extend beyond the request and reply message processing performed by IBM MQ . Any work performed within the service might get rerun as a result of a failure which causes the message to be received again. The following diagram shows the scope of the transaction:

Assured delivery is enabled by applying the AssuredDelivery attribute to the service class as shown in the following example:
[AssuredDelivery]
class TestCalculatorService : IWMQSampleCalculatorContract
{
    public int add(int a, int b)
    {
        int ans = a + b;
        return ans;
    }
}
When using the AssuredDelivery attribute, we must be aware of the following points:

  • When a channel determines that a failure is likely to recur if a message was rolled-back and received again, the message is treated as a poison message and is not returned to the request queue for reprocessing. For example: If the received message is not correctly formatted or cannot be dispatched to a service. Unhandled exceptions thrown from a service operation are always resent until the message has been redelivered the maximum number of times specified by the backout threshold property of the request queue. For more information, see: WCF custom channel poison messages
  • The channel performs the reading, processing, and replying of each request message as an atomic operation using a single thread of execution to enforce transactional integrity. To enable service operations to run concurrently, the channel enables WCF to create multiple instances of the channel. The number of channel instances available for processing requests is controlled by the binding property MaxConcurrentCalls. For more information, see: WCF binding configuration options
  • The assured delivery function uses both the IOperationInvoker and the IErrorHandler WCF extensibility points. If these extensibility points are used externally by an application, the application must ensure that any previously registered extensibility points are called. Failure to do so for IErrorHandler can result in errors going unreported. Failure to do so for IOperationInvoker can cause WCF to stop responding.

Parent topic: WCF Custom channel features and capabilities