The Publish-Subscribe Framework

The source code available with this book contains a complete publish-subscribe example. I wanted not just to provide sample publish-subscribe services and clients, but also to provide a general-purpose framework that automates implementing such services and adding the support for any application. The first step in building the framework was to factor the publish-subscribe management interfaces, and provide separate contracts for transient and persistent subscriptions and for publishing.[*]

Managing Transient Subscriptions

For managing transient subscriptions, I defined the ISubscriptionService interface shown in Example B-1.

Example B-1. The ISubscriptionService interface manages transient subscribers

public interface ISubscriptionService
   void Subscribe(string eventOperation);

   void Unsubscribe(string eventOperation);

Note that ISubscriptionService does not identify the callback contract its implementing endpoint expects. Being a general-purpose interface, it is unaware of particular callback contracts. It is up to the using application to define those callback contracts. The callback interface is provided in the using application by deriving from ISubscriptionService and specifying the desired callback contract:

interface IMyEvents { [OperationContract(IsOneWay = true)] void OnEvent1( ); [OperationContract(IsOneWay = true)] void OnEvent2(int number); [OperationContract(IsOneWay = true)] void ...

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.