Events

The basic WCF callback mechanism does not indicate anything about the nature of the interaction between the client and the service. They could be equal peers in a commutative interaction, each calling and receiving calls from the other.

However, the canonical use for duplex callbacks is with events. Events allow the client or clients to be notified about something that occurred on the service side. The event may result from a direct client call, or it may be the result of something the service monitors. The service firing the event is called the publisher, and the client receiving the event is called the subscriber. Events are a required feature in almost any type of application, as shown in Figure 5-2.

A publishing service can fire events at multiple subscribing clients

Figure 5-2. A publishing service can fire events at multiple subscribing clients

While events in WCF are noting more than callback operations, by their very nature events usually imply a looser relationship between the publisher and the subscriber, compared with the relationship between a client and a service. When dealing with events, the service typically publishes the same event to multiple subscribing clients. The publisher often does not care about the order of the invocation of the subscribers. The publishing service usually does not care about errors the subscribers might have while processing the events. All the publisher knows is that it should deliver ...

Get Programming WCF Services now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.