WCF Publish Subscribe–A Full Example – The Service Side Part 1 (Interface)

This entry is part 2 of 6 in the series WCF Publish Subscribe - A Full Example in C#, Step by Step

The Service code consists of an Interface (IMagazineService) and its implementation (MagazineService).

The Interface defines all the capabilities of the service. What do we really want from a Publisher service?

  1. A Publish method (called PublishMagazine)
  2. A Subscribe method (to allow clients to subscribe to the service)
  3. An Unsubscribe method (to allow clients to unsubscribe from the service)

Those are the three main things we need from our Publisher service. As long as all we need is the Publisher to get in touch with multiple subscribers, we are all set.

However, we also need a way to notify individual clients (subscribers) who have subscribed to our service. 

This can be handled via a Callback method (called MessageReceived in our example). The Callback method is best made available as part of a separate interface (known as IClientContract).

public interface IClientContract

{

    [OperationContract(IsOneWay = true)]

    void MessageReceived(string hyperlinkToNewIssue, string issueNumber, DateTime datePublished);

}

[ServiceContract(SessionMode = SessionMode.Required, CallbackContract = typeof(IClientContract))]

public interface IMagazineService

{

    [OperationContract(IsOneWay = false, IsInitiating = true)]

    void PublishMagazine(string hyperLinkToIssue, string issueNumber, DateTime datePublished);

    [OperationContract(IsOneWay = false, IsTerminating = true)]

    void Subscribe();

    [OperationContract(IsOneWay = false, IsTerminating = true)]

    void Unsubscribe();

 

}

 

public interface IClientContract

{

    [OperationContract(IsOneWay = true)]

    void MessageReceived(string hyperlinkToNewIssue, string issueNumber, DateTime datePublished);

}

Cloud Advisory Services | Security Advisory Services | Data Science Advisory and Research

Specializing in high volume web and cloud application architecture, Anuj Varma’s customer base includes Fortune 100 companies (dell.com, British Petroleum, Schlumberger).

All content on this site is original and owned by AdverSite Web Holdings, Inc. – the parent company of anujvarma.com. No part of it may be reproduced without EXPLICIT consent from the owner of the content.

Anuj Varma – who has written posts on Anuj Varma, Technology Architect.


Series NavigationWCF and Publish Subscribe– A Full Example: IntroductionWCF Publish Subscribe– A Full Example: The Service Side Part 2 (Implementation)

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *