SOA with .NET and Windows Azure : WCF Discovery (part 2) - Locating a Service Ad Hoc & Sending and Receiving Service Announcements

2/16/2011 5:53:58 PM

Locating a Service Ad Hoc

A service consumer can send out WS-Discovery probe messages to locate available services. The probe query can include compatibility criteria, such as a service contract or a service scope. Query parameters are encoded in a FindCriteria object.

There are two types of query criteria:

  • contract type names – searches for services with endpoints that implement the specified contract names

  • scope – searches for services with endpoints that match the specified scope (scopes are defined in the endpoint’s behavior and several matching options for complete or partial matches exist)

The DiscoveryClient class provided by WCF manages probes and raises FindProgressChangedEventArgs events when ProbeMatch responses come in:

discoveryClient =
new DiscoveryClient(new UdpDiscoveryEndpoint());
discoveryClient.FindProgressChanged +=
new EventHandler<FindProgressChangedEventArgs>
discoveryClient.FindCompleted +=
new EventHandler<FindCompletedEventArgs>
(new FindCriteria(typeof(ICustomerService)),

Following this, we are submitting an asynchronous discovery query over UDP. ParseResult examines the service contract, scope, and metadata to determine if the responding service meets the requirements:

Example 4.
private void OnFindProgressChanged(
object sender, FindProgressChangedEventArgs e)

The DiscoveryClient class also implements a synchronous Find() method that takes a FindCriteria parameter that specifies query and query completion criteria, such as the number of responses or the time to wait for responses.

DiscoveryClient also exposes a Resolve() method to locate a replacement for a service that’s been previously available at a known address. Calling Resolve() follows the same pattern as Find().

Sending and Receiving Service Announcements

Services can announce their availability when they come online or go offline. These announcements can be received by all services listening for them. You configure a service to transmit announcements by adding announcementEndpoints to the serviceDiscovery behavior, as shown in Example 6.20. The service then issues announcements to the configured endpoint.

Example 5.
<behavior name="DiscoveryBehavior">
<endpoint name="udpEndpointName"

The standard udpAnnouncementEndpoint is preconfigured in WCF. Each announcement includes the service endpoint location and contract, as well as endpoint-specific metadata.

In highly dynamic environments, service consumers may want to track available services instead of probing for availability or relying on the discovery proxy. Probing introduces additional latency and therefore should not occur as part of the logic that resolves service locations. Frequent multicast probing further results in unnecessary network traffic. Instead, a consumer of dynamically available services can listen for announcement broadcasts and maintain its own list of services.

Services interested in receiving local UDP discovery announcements must open up a listener on the udpAnnouncementEndpoint endpoint. WCF provides a pre-built AnnouncementService class to handle service announcements. This class can raise the OnOnlineAnnouncement and OnOfflineAnnouncement events to the hosting application.

This example shows a listener configured for announcement services:

Example 6.
... application service information ...

<service name="AnnouncementListener">
<endpoint kind="udpAnnouncementEndpoint" />

Next, we register events with AnnouncementService:

Example 7.
AnnouncementService announcementService =
new AnnouncementService();
announcementService.OnlineAnnouncementReceived +=
new EventHandler<AnnouncementEventArgs>
announcementService.OfflineAnnouncementReceived +=
new EventHandler<AnnouncementEventArgs>

The events receive an EndpointDiscoveryMetadata object, just like the response to a discovery probe. A FindCriteria object determines if the metadata matches endpoint requirements. In the following example, we query an EndpointDiscoveryMetadata announcement for compatibility with the ICustomerService contract:

Example 8.
private void OnlineAnnouncement
(object sender, AnnouncementEventArgs e)
EndpointDiscoveryMetadata metadata =
FindCriteria criteria =
new FindCriteria(typeof(ICustomerService));
if (criteria.IsMatch(metadata))
... further examine endpoint metadata ...
... store endpoint address for service access ...
Other -----------------
- Windows 7 : Working with Network Files Offline (part 3) - Prohibiting a Network Folder from Being Made Available Offline & Encrypting Offline Files
- Windows 7 : Working with Network Files Offline (part 2) - Changing the Amount of Disk Space Used by Offline Files
- Windows 7 : Working with Network Files Offline (part 1) - Activating the Offline Files Feature & Making a File or Folder Available for Offline Use
- Windows 7 : Sharing Resources with the Network (part 2) - Monitoring Your Shared Resources
- Windows 7 : Sharing Resources with the Network (part 1) - Setting Sharing Options & Creating User Accounts for Sharing
- Windows 7 : Accessing a Shared Printer
- Windows 7 : Creating a Network Location for a Remote Folder
- Windows Vista: Windows Reliability and Performance Monitor and Task Manager
- Windows Vista: Configuring Internet Explorer 7.0 - Dynamic Security and Protected Mode
- Windows 7: Mapping a Network Folder to a Local Drive Letter
- SOA with .NET and Windows Azure: WCF Extensions - WCF Router (part 2) - Routing Configuration
- SOA with .NET and Windows Azure: WCF Extensions - WCF Router (part 1) - The RoutingService Class & Routing Contracts
- Windows 7: Accessing Shared Network Resources
- Windows 7: Managing Wireless Network Connections (part 4) - Creating User-Specific Wireless Connections
- Windows 7: Managing Wireless Network Connections (part 3) - Reordering Wireless Connections
- Windows 7: Managing Wireless Network Connections (part 2) - Working with Wireless Connection Properties
- Windows 7: Managing Wireless Network Connections (part 1) - Creating an Ad Hoc Wireless Network
- Windows7: Managing Network Connections (part 5) - Using a Network Connection to Wake Up a Sleeping Computer
- Windows7: Managing Network Connections (part 4) - Finding a Connection’s MAC Address
- Windows7: Managing Network Connections (part 3) - Setting Up a Static IP Address
- First look: Apple Watch

- 10 Amazing Tools You Should Be Using with Dropbox

- Sigma 24mm f/1.4 DG HSM Art

- Canon EF11-24mm f/4L USM

- Creative Sound Blaster Roar 2

- Alienware 17 - Dell's Alienware laptops

- Smartwatch : Wellograph

- Xiaomi Redmi 2
Popular tags
Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Biztalk Exchange Server Microsoft LynC Server Microsoft Dynamic Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Indesign Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe After Effects Adobe Photoshop Adobe Fireworks Adobe Flash Catalyst Corel Painter X CorelDRAW X5 CorelDraw 10 QuarkXPress 8 windows Phone 7 windows Phone 8