BizTalk RFID 2009 ships a Discovery library that provides an easy interface to leverage WS-Discovery to discover WS-Discovery enabled devices. WS-Discovery support was first included with the BizTalk RFID Standards Pack and comes out of the box with BizTalk RFID 2009.
The Discovery library is intended for the use of provider writers to help them easily discover devices that support WS-Discovery. The WS-Discovery protocol uses SOAP and UDP multicast to enable services to be discovered by a client. In the BizTalk RFID world, services discovered are RFID devices and the client is a BizTalk RFID provider.
Here’s a quick view of the messages that the Discovery library supports sending (or receiving) and their function in the WS-Discovery protocol:
- Hello - A service (the device) sends a Hello message by using UDP multicast when it joins a network
- Bye - A service sends a Bye message when it prepares to leave the network
- Probes - A client (the BizTalk RFID provider) sends a Probe message by using UDP multicast looking for services it is interested in. Matching services respond with ProbeMatch messages
A provider writer chiefly needs to work with the class WSDiscoveryForDspi in namespace Microsoft.Rfid.Discovery. Here’s a wrap of the methods in this class, their functionality, and where they fit in the provider:
- StartDiscovery
o This method causes the discovery library to start listening for Hello and Bye messages on the network.
o This should be called from within the DeviceProvider.StartDiscovery() method.
o To respond to Hello and Bye messages, the provider should subscribe to the events OnDeviceAdded and OnDeviceRemoved exposed by the WSDiscoveryForDspi class. OnDeviceAdded is raised when a Hello is received and OnDeviceRemoved is raised when a Bye is received.
o The StartDiscovery method can be passed a MatchCriteria argument to limit the range of devices that are searched. See here for details.
public override void StartDiscovery()
{
m_discoveryForDspi.StartDiscovery(m_matchCriteriaRfidDeviceType);
}
- StopDiscovery
o This stops the listening for Hello and Bye messages
o Should be called from within the DeviceProvider.StartDiscovery() method.
- SearchAsync
o This causes the Discovery library to send a Probe and wait for ProbeMatch messages
o The time duration of the wait for ProbeMatch is defined by MatchTimeout property of the WSDiscoveryForDspi class. After the time is up the SearchCompleted event is raised
o On receiving a ProbeMatch, the OnDeviceAdded event is raised
o This can also be passed MatchCriteria like the StartDiscovery method.
o This should be called from within the TriggerDiscovery method
Handling the OnDeviceAdded event – If an OnDeviceAdded event is received (i.e. either a Hello or a ProbeMatch was received from a device), the provider has found a device successfully. That means it should raise a DiscoveryEvent to the BizTalk RFID service. The OnDeviceAdded event passes a WSDiscoveryEventArgs argument to the event handler method. This has a number of useful properties that give the XAddrs element, Types element etc in the Hello or ProbeMatch message from the device. This argument needs to be converted to the type DiscoveryEventArgs understood by the BizTalk RFID service. The Discovery library provides a utility method for this - ConvertToDspiDiscoveryEventArgs - the use of which is shown below.
void discoveryForDSPI_OnDeviceAdded(object sender, WSDiscoveryEventArgs e)
if (DiscoveryEvent != null)
DiscoveryEventArgs args = discoveryForDSPI.ConvertToDspiDiscoveryEventArgs(e);
DiscoveryEvent(this, args);
A WS-Discovery sample provider is included in the BizTalk RFID 2009 samples and can be used as a base for developing WS-Discovery providers.
References:
Standards support in BizTalk RFID 2009 http://blogs.msdn.com/krishg/archive/2009/03/26/biztalk-rfid-and-standards-support.aspx
DiscoveryLibrary documentation http://msdn.microsoft.com/en-us/library/dd298783.aspx