WCF and Publish Subscribe–A Full Example: The Event Generator

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

The purpose of the Event Generator code is to publish events (New Magazine Issue Available)  that subscribers will get notified about.

  1. Add a new Console App (Add New Project) to the WCFPublishSubscribe solutionCall it EventGenerator.
  2. Copy over the app.config and the generatedProxy.cs to this new project.
  3. Publishing an event is as simple as invoking the Publish method (PublishMagazine) on the client (proxy class)
myClient.PublishMagazine("http://www.anujvarma.com", "Vol1: Issue1", System.DateTime.Now);

class EventGenerator: IMagazineServiceCallback


        static void Main(string[] args)


            // always create an instance context to associate the service with            

            InstanceContext siteHostContext = new InstanceContext(null, new EventGenerator());

            MagazineServiceClient myClient = new MagazineServiceClient(siteHostContext);


            Console.WriteLine("Publishing New Issue(http://www.anujvarma.com, Vol1: Number1, )");

            myClient.PublishMagazine("http://www.anujvarma.com", "Vol1: Issue1", System.DateTime.Now);



            Console.WriteLine("Press ENTER to stop publishing events");



            //Closing the client gracefully closes the connection and cleans up resources




        public void MessageReceived(string linkToNewIssue, string issueNumber, DateTime publishDate)


            Console.WriteLine("MessageReceived(item{0}, item{1}, item{2}", linkToNewIssue, issueNumber, publishDate);



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 Publish Subscribe– A Full Example: The Service Side Part 2 (Implementation)WCF and Publish Subscribe–A Full Example: Client Code

1 Comment

Leave a Reply

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