O'Reilly logo

Programming WCF Services, 3rd Edition by Juval Lowy

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Callbacks

Callback contracts, just like service contracts, can propagate the service transaction to the callback client. To enable this you apply the TransactionFlow attribute, as with a service contract. For example:

interface IMyContractCallback
{
   [OperationContract]
   [TransactionFlow(TransactionFlowOption.Allowed)]
   void OnCallback();
}
[ServiceContract(CallbackContract = typeof(IMyContractCallback))]
interface IMyContract
{...}

The callback method implementation can use the OperationBehavior attribute (just like a service operation) and specify whether to require a transaction scope and auto-completion:

class MyClient : IMyContractCallback
{
   [OperationBehavior(TransactionScopeRequired = true)]
   public void OnCallback()
   {
      Transaction transaction = Transaction.Current;
      Debug.Assert(transaction != null);
   }
}

Callback Transaction Modes

The callback client can have four modes of configuration: Service, Service/Callback, Callback, and None. These are analogous to the service transaction modes, except the service now plays the client role and the callback plays the service role. For example, to configure the callback for the Service transaction mode (that is, to always use the service’s transaction), follow these steps:

  1. Use a transaction-aware duplex binding with transaction flow enabled.

  2. Set transaction flow to mandatory on the callback operation.

  3. Configure the callback operation to require a transaction scope.

Example 7-30 shows a callback client configured for the Service transaction mode. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required