Skip to Content
Programming WCF Services
book

Programming WCF Services

by Juval Lowy
February 2007
Intermediate to advanced
634 pages
16h 1m
English
O'Reilly Media, Inc.
Content preview from Programming WCF Services

Callbacks

Callback contracts, just like service contracts, can propagate the service transaction to the callback client. 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 requiring 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, analogous to the service transaction modes, except the service now plays the client role and the callback plays the service role in the previous service-side modes. For example, to configure the callback for Service transaction mode (that is, always using the service 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-25 shows a callback client configured for Service transaction.

Example 7-25. Configuring ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming WCF Services, 2nd Edition

Programming WCF Services, 2nd Edition

Juval Lowy
Pro WCF: Practical Microsoft SOA Implementation

Pro WCF: Practical Microsoft SOA Implementation

Chris Peiris, Dennis Mulder, Shawn Cicoria, Amit Bahree, Nishith Pathak
Mastering ASP.NET Web API

Mastering ASP.NET Web API

Mithun Pattankar, Malendra Hurbuns

Publisher Resources

ISBN: 0596526997Supplemental ContentErrata Page