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 and Client Safety

There are quite a few cases when a client might receive concurrent callbacks. If the client provided a callback reference to multiple services, those services could call back concurrently to the client. But even with a single callback reference, the service might launch multiple threads and use all of them to call on that single reference. Duplex callbacks enter the client on worker threads and might corrupt the client state if done concurrently without synchronization. The client must synchronize access to its own in-memory state, but also to any resources the callback thread might access. Similar to a service, a callback client can use either manual or declarative synchronization. The CallbackBehavior attribute introduced in Chapter 6 offers the ConcurrencyMode and the UseSynchronizationContext properties:

[AttributeUsage(AttributeTargets.Class)]
public sealed class CallbackBehaviorAttribute : Attribute,...
{
   public ConcurrencyMode ConcurrencyMode
   {get;set;}
   public bool UseSynchronizationContext
   {get;set;}
}

Both of these properties default to the same values as with the ServiceBehavior attribute and behave in a similar manner. For example, the default of the ConcurrencyMode property is ConcurrencyMode.Single, so these two definitions are equivalent:

class MyClient : IMyContractCallback
{...}

[CallbackBehavior(ConcurrencyMode = ConcurrencyMode.Single)]
class MyClient : IMyContractCallback
{...}

Callbacks with ConcurrencyMode.Single

When the callback ...

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