Announcements Sample

This sample shows how to use the Announcement functionality of the Discovery feature. Announcements allow services to send out announcement messages that contain metadata about the service. By default a hello announcement is sent when the service starts up and a bye announcement is sent when the service shuts down. These announcements can be multicast or they can be sent point-to-point. This sample consists of two projects service and client.

This project contains a self-hosted calculator service. In the Main method, a service host is created and a service endpoint is added to it. Next, a ServiceDiscoveryBehavior is created. To enable announcements, an announcement endpoint must be added to the ServiceDiscoveryBehavior. In this case a standard endpoint, using UDP multicast is added as the announcement endpoint. This broadcasts the announcements over a well-known UDP address.

In this project, note that the client hosts an AnnouncementService. Furthermore, two delegates are registered with events. These events dictate what the client does when online and offline announcements are received.

To use this sample

This sample uses HTTP endpoints and to run this sample, proper URL ACLs must be added see Configuring HTTP and HTTPS for details. Executing the following command at an elevated privilege should add the appropriate ACLs. You may want to substitute your Domain and Username for the following arguments if the command does not work as is. netsh http add urlacl url=http://+:8000/ user=%DOMAIN%\%UserName%

Build the solution.

Run the client.exe application.

Run the service.exe application. Note the client receives an online announcement.

Close the service.exe application. Note the client receives an offline announcement.

Important

The samples may already be installed on your machine. Check for the following (default) directory before continuing.