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("https://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(https://www.anujvarma.com, Vol1: Number1, )");

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

 

            Console.WriteLine();

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

            Console.ReadLine();

 

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

            myClient.Close();

        }

 

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

        {

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

        }

    }

Anuj holds professional certifications in Google Cloud, AWS as well as certifications in Docker and App Performance Tools such as New Relic. He specializes in Cloud Security, Data Encryption and Container Technologies.

Initial Consultation

Anuj Varma – who has written posts on Anuj Varma, Hands-On Technology Architect, Clean Air Activist.


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