wcf.net-4.0service-discoverywcf-discovery

"Re-announcing" service periodically when using WCF ServiceDiscoveryBehavior announcement endpoint?


I have a Managed Discovery Service hosted with a known URI. I have a discoverable service that when it starts, it announces itself using an AnnouncementEndpoint added to the ServiceDiscoveryBehavior of the service.

The specific use case I would like to solve is the following:

  1. Managed Discovery service starts.
  2. A discoverable service starts and announces itself to the Managed Discovery service.
  3. The Managed Discovery service is restarted (for any various possible reasons).

How then does the discoverable service refresh itself (re-announce) to the Managed Discovery service?

I know the Managed Discovery service can persist endpoints and restore them upon start but I want everything to be dynamic and self repairing so that there's no chance of stale endpoint information.

An alternative use case would be:

  1. An existing discoverable service is running.
  2. A new Managed Discovery service is brought online.

How do we force or invoke the same Announcement service contract call to the new Managed Discovery service?

I hope this is enough information about what I want to accomplish.


Solution

  • I found the answer myself. In the scenario where you need to control announcements outside of the ServiceDiscoveryBehavior , you would use the AnnouncementClient class.

    AnnouncementClient client = new AnnouncementClient(announcementEndpoint);
    var endpointDiscoveryMetadata = EndpointDiscoveryMetadata.FromServiceEndpoint(netTcpEndpoint);
    
    client.AnnounceOnline(endpointDiscoveryMetadata);