WCF and Publish Subscribe–A Full Example: The Event Generator
- WCF and Publish Subscribe– A Full Example: Introduction
- WCF Publish Subscribe–A Full Example – The Service Side Part 1 (Interface)
- WCF Publish Subscribe– A Full Example: The Service Side Part 2 (Implementation)
- WCF and Publish Subscribe–A Full Example: The Event Generator
- WCF and Publish Subscribe–A Full Example: Client Code
- WCF and Publish Subscribe–A Full Example: Running the Client (Subscriber)
The purpose of the Event Generator code is to publish events (New Magazine Issue Available) that subscribers will get notified about.
- Add a new Console App (Add New Project) to the WCFPublishSubscribe solution. Call it EventGenerator.
- Copy over the app.config and the generatedProxy.cs to this new project.
- 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);
}
}
You say this is a full example, where is the error handling code ?