Using WS-Discovery in WCF 4.0

Runtime endpoint discovery is one of the most challenging capabilities to implement in service oriented systems. Dynamically resolving service’s endpoints based on predefined criteria is a necessary functionality to interact with services which endpoint addresses change frequently. WS-Discovery is an OASIS Standard that defines a lightweight discovery mechanism for discovering services based on multicast messages. Essentially, WS-Discovery enables a service to send a Hello announcement message when it is initialized and a Bye message when is removed from the network. Clients can discover services by multicasting a Probe message to which a service can reply with a ProbeMatch message containing the information necessary to contact the service. Additionally, clients can find services that have changed endpoint by issuing a Resolve message to which respond with a ResolveMatch message.

 

Figure: WS-Discovery conceptual model

Contrary to other WS-* protocols, WS-Discovery has found a great adoption among the network device builders as it allows to streamline the interactions between these type of devices. For instance, a printer can use WS-Discovery to announce its presence on a network so that it can be discovered by the different applications that require printing documents. Windows Vista's contact location system is another example of a technology based on WS-Discovery.

The 4.0 release of Windows Communication Foundation includes an implementation of WS-Discovery that enables service’s endpoints as runtime discoverable artifacts. WCF enables the WS-Discovery capabilities in two fundamental models: Managed and Ad-Hoc. The managed mode assumes a centralized component called service proxy that serves as a persistent repository for all the services in a network. When a service is initialized it publishes its details to the discovery proxy so that it becomes accessible the the different clients in the network.

Contrary to the managed model, the Ad-Hoc mechanism does not rely on a centralized discovery proxy. In this model, services publish their presence in a network by multicasting announcement message that can be processed by the interested consumers. Additionally, clients can also multicast discover messages through the network in order to find a service that matches predefined criteria.

WCF's WS-Discovery managed mode will be the subject on a future post. Today we would like to illustrate the details of enabling dynamic discovery using the WS-Discovery 's Ad-Hoc model in WCF 4.0. This model is traditionally simpler to implement than the managed model although it can introduce some challenges from the management standpoint.

WCF 4.0 abstracts the WS-Discovery Ad-Hoc model using the ServiceDiscoveryBehavior which indicates that a service can be discoverable and the UdpDiscoveryEndpoint that instantiates a service endpoint that can listen for discovery requests. The remaining of this post will provide a practical example of the use of the WS-Discovery Ad-Hoc model in WCF 4.0

Let’s start with the following WCF service.

   1:      public class SampleService: ISampleService
   2:      {
   3:          public string Echo(string msg)
   4:          {
   5:              return msg;
   6:          }
   7:      }
   8:   
   9:      [ServiceContract]
  10:      public interface ISampleService
  11:      {
  12:          [OperationContract]
  13:          string Echo(string msg);
  14:      }

Figure: Sample WCF Service

In order to make the service discoverable we first need to add the ServiceDiscoveryBehavior to the service behavior’s collection. As explained previously, this behavior indicates to the WCF runtime that the service supports the WS-Discovery protocol.

   1:  using (ServiceHost host = new ServiceHost(typeof(SampleService), new Uri(base uri...)))
   2:  {
   3:   ...
   4:    host.AddServiceEndpoint(typeof(ISampleService), new BasicHttpBinding(), String.Empty);
   5:    ServiceDiscoveryBehavior discoveryBehavior= new ServiceDiscoveryBehavior();             
   6:    host.Description.Behaviors.Add(discoveryBehavior);
   7:    ...       
   8:  }

Figure: Adding the service discovery behavior

The next step is to add the UdpDiscoveryEndpoint to the list of service endpoints so that our service can start listening for WS-Discovery messages.

   1:   host.AddServiceEndpoint(new UdpDiscoveryEndpoint());

Figure: Adding an UDP discovery endpoint

At this point our service is ready to receive and interpret WS-Discovery messages from the different clients on the network. However those clients are not yet aware of the existence of the service given that this one hasn’t published the Hello announcement message. We can accomplish this by simply adding a new UdpAnnoucement endpoint to the list of service endpoints.

   1:   discoveryBehavior.AnnouncementEndpoints.Add(new UdpAnnouncementEndpoint());

Figure: Adding an UDP announcement endpoint

In order to dynamically discover services using the Ad-Hoc model, a WCF client instantiates a DiscoveryClient that uses discovery endpoint specifying where to send Probe or Resolve messages. The client then calls Find that specifies search criteria within a FindCriteria instance. If matching services are found, Find returns a collection of EndpointDiscoveryMetadata. The following code illustrates that concept.

   1:   DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
   2:   FindResponse discoveryResponse= discoveryClient.Find(new FindCriteria(typeof(ISampleService)));
   3:   EndpointAddress address = discoveryResponse.Endpoints[0].Address;
   4:   
   5:  SampleServiceClient service = new SampleServiceClient(new BasicHttpBinding(), address);
   6:  service.Echo("WS-Discovery test");

Figure: WCF WS-Discovery client

The WCF implementation of the WS-Discovery Ad-Hoc model presents various aspects that I think are worth highlighting. First, WCF uses specialized discovery and announcement endpoints to process WS-Discovery messages isolating them from the service’s messages. Additionally, the use of service behaviors allow developers to incorporate the WS-Discovery capabilities as they are required without interfering with the normal service functioning. Finally, WCF clients can simply use the discovery client to dynamically resolve the service endpoint without having to make major modifications to its business logic.

We will cover the WS-Discovery managed mode in a future post.

Comments

Friday, February 13, 2009 11:15 AM by Using WS-Discovery in WCF 4.0 - Jesus Rodriguez's WebLog

# Using WS-Discovery in WCF 4.0 - Jesus Rodriguez's WebLog

Pingback from  Using WS-Discovery in WCF 4.0 - Jesus Rodriguez's WebLog

Friday, February 13, 2009 12:38 PM by Daniel

# re: Using WS-Discovery in WCF 4.0

Interesting- kind of like IoC for services... One comment: in my experience, all this WS-* stuff breaks down pretty quickly when you have to interop with non-.NET clients.  I realize that MS can't exactly make Java/PHP/Ruby/etc play with WS-*, but it's annoying to have these "open" standards that get thrown out the window the second we have to talk to non-.NET systems.  Invariably, even large SOA companies have told us "just use plain SOAP 1.1 over SSL".

# BizTalk Linkflood, February 14, 2009 « ADA ICT Devsquad’s Blog

Pingback from  BizTalk Linkflood, February 14, 2009 « ADA ICT Devsquad’s Blog

Saturday, February 14, 2009 5:10 PM by DotNetShoutout

# Using WS-Discovery in WCF 4.0

Thank you for submitting this cool story - Trackback from DotNetShoutout

Sunday, February 15, 2009 8:44 PM by hanson

# re: Using WS-Discovery in WCF 4.0

I always problem with this Error "Target of Invocation" when i use wcf ws-Eventing(publish/Sub model), whenever client disconnected or busy to receive message from wcf service.

Any idea to solve it?

Tuesday, February 17, 2009 11:07 AM by Using WS-Discovery in WCF 4.0 | DavideZordan.net

# Using WS-Discovery in WCF 4.0 | DavideZordan.net

Pingback from  Using WS-Discovery in WCF 4.0 | DavideZordan.net

Tuesday, March 03, 2009 3:28 AM by Nicholas Allen's Indigo Blog

# Introduction to Ad Hoc Discovery

Jesus Rodriguez has a description of WS-Discovery that covers examples in WCF 4.0 for ad hoc discovery

Sunday, March 08, 2009 5:09 PM by Tim Cools

# Discover your devices

Discover your devices

Monday, March 09, 2009 4:33 AM by Claudio

# re: Using WS-Discovery in WCF 4.0

Jesus may you try if FW4 WSDiscovery implementation works with mime (www.codeproject.com/.../ws-discovery.aspx)? Thank you

Claudio

Monday, March 09, 2009 6:03 PM by Tim Cools

# Discover your devices

Discover your devices

Tuesday, March 24, 2009 11:59 AM by Leonid Shirmanov

# re: Using WS-Discovery in WCF 4.0

It's really nice to figure out how extandable WCF architecture is. Just added Service Behavior to the server side.

Thursday, March 26, 2009 12:49 AM by Travis Spencer - Software Engineer

# WCF Discovery

Microsoft announced at PDC '08 that .NET 4.0 would include an implementation of WS-Discovery. Conformance to this protocol would allow service consumers to locate providers dynamically at run-time. I'm sure I don't have to tell you that this capability

# linkfeedr » Blog Archive » Using WS-Discovery in WCF 4.0 - RSS Indexer (beta)

Pingback from  linkfeedr » Blog Archive » Using WS-Discovery in WCF 4.0 - RSS Indexer (beta)

Friday, May 08, 2009 7:02 PM by I Love C#

# What’s New in WCF 4.0?

What’s New in WCF 4.0? בתקופה האחרונה אני משקיע הרבה זמן על ללמוד את החידושים  בדוט-נט 4.0 ובפרט

Friday, May 08, 2009 7:04 PM by I LOVE C#

# What’s New in WCF 4.0?

What’s New in WCF 4.0? בתקופה האחרונה אני משקיע הרבה זמן על ללמוד את החידושים  בדוט-נט 4.0 ובפרט

Wednesday, May 13, 2009 4:34 PM by Kevin

# re: Using WS-Discovery in WCF 4.0

Hi,

Do you know some scenario where can I use this feature?

Thursday, May 14, 2009 6:29 PM by Tim Cools

# Discover your devices

Discover your devices

Thursday, May 28, 2009 12:39 AM by Adam Langley

# re: Using WS-Discovery in WCF 4.0

All the discovery examples I have seen assume basic HTTP as the binding.

Is there any facility in discovery for also publishing the binding requirements to talk to the advertised endpoint?

It seems to me that its a bit of a defecit if the client must 'assume' the protocol and security requirements, when it could be passed in the discovery meta-data.

Thanks

Wednesday, June 24, 2009 12:11 AM by Shrishail

# re: Using WS-Discovery in WCF 4.0

Can WCF be used with the Compact Framework v3.5?

regards,

Shrishail

Sunday, September 06, 2009 10:03 AM by Tim Cools

# Discover your devices

Discover your devices

Wednesday, December 30, 2009 11:44 AM by Escort agency New York City

# re: Using WS-Discovery in WCF 4.0

It is extremely interesting for me to read the article. Thanks for it. I like such topics and everything connected to them. I definitely want to read a bit more on that blog soon.

Saturday, January 23, 2010 6:36 PM by OrdinarySomething

# re: Using WS-Discovery in WCF 4.0

It was certainly interesting for me to read that blog. Thanx for it. I like such themes and everything connected to this matter. BTW, try to add some photos :).

# WCF 4 Routing Service Multicast sample « Danny Cohen's PSRTG

Pingback from  WCF 4 Routing Service Multicast sample «  Danny Cohen's PSRTG

Wednesday, April 21, 2010 2:52 PM by Natraj

# re: Using WS-Discovery in WCF 4.0

Hello Sir,

REF : WCF Discovery - Probe Match message.

I would like to know how do I modify probe match message at run time.i have  this requirement that i have to added element to the probe match before sending to the client,

I have tried this using message inspector but it is not working during probe match message exchange the message null, not sure why this is happening

you have pointer please let me know

Thank You,

Natraj Mustoori

Wednesday, July 07, 2010 9:17 AM by FrequentlyHere

# re: Using WS-Discovery in WCF 4.0

Interesting article you got here. I'd like to read more concerning this topic. The only thing it would also be great to see on this blog is some pictures of some gizmos.

Alex Trider

<a href="www.jammer-store.com/">cell phone jammers</a>

Sunday, July 11, 2010 9:30 PM by hot escorts

# re: Using WS-Discovery in WCF 4.0

It is rather interesting for me to read that blog. Thanx for it. I like such themes and everything that is connected to this matter. I definitely want to read more on that blog soon. By the way, pretty nice design you have at that site, but don’t you think it should be changed once in a few months?

Kate Swift

Thursday, July 22, 2010 8:45 AM by woman escorts

# re: Using WS-Discovery in WCF 4.0

Truly good article to spend some time on reading it to my thinking. By the way, why haven't you you submit this post to social bookmarking sites? It should bring lots of traffic to this blog.

Sunday, July 25, 2010 9:33 PM by escort brazilian

# re: Using WS-Discovery in WCF 4.0

I would like to read a bit more on that site soon. BTW, rather nice design your blog has, but don’t you think design should be changed from time to time?

Hannah William

Wednesday, July 28, 2010 2:47 AM by brunette London

# re: Using WS-Discovery in WCF 4.0

Rather nice site you've got here. Thanks the author for it. I like such themes and everything that is connected to them. I would like to read a bit more on that blog soon.

Hilary Simpson

# Web Service Discovery in SO-Aware (Part 2) &laquo; D Goins Espiriance

Pingback from  Web Service Discovery in SO-Aware (Part 2) &laquo; D Goins Espiriance

Wednesday, September 01, 2010 5:08 AM by escort zurich

# re: Using WS-Discovery in WCF 4.0

Don't stop posting such stories. I like to read articles like this. Just add some pics :)

# ??????????????? &raquo; Blog Archive &raquo; WCF4.0???????????????(11):????????????WS-Discovery?????????FindCriteria

Pingback from  ???????????????  &raquo; Blog Archive   &raquo; WCF4.0???????????????(11):????????????WS-Discovery?????????FindCriteria

Saturday, October 02, 2010 1:58 AM by Joan Hakkinen

# re: Using WS-Discovery in WCF 4.0

It is extremely interesting for me to read that post. Thanks for it. I like such topics and everything connected to this matter. I definitely want to read a bit more soon.

Joan Hakkinen

<a href="irelandescortdirectory.com/.../dublin-escorts">escort in dublin</a>

Tuesday, November 30, 2010 12:32 PM by &#32654;&#22269;&#21326;&#20154;

# re: Using WS-Discovery in WCF 4.0

I am seriously not too acquainted with this topic but I do like to go to weblogs for layout suggestions and interesting subjects. You truly expanded upon a subject that I normally don't care a lot about and created it extremely amazing. This really is a nice webpage that I'll consider observe of. I currently bookmarked it for future reference. Cheers

--------------------------------------------

<a href="xiangyan.info/2-p-49.html">New York &#21326;&#20154;</a>

Also welcome you!

Friday, December 03, 2010 7:09 PM by cool skateboard designs

# re: Using WS-Discovery in WCF 4.0

"I do not know about you fellows but for me the layout of a blog is incredibly crucial, nearly as a lot as the write-up itself.  Furthermore I'm a real mug for picture  clips.!!!. or, as a matter of fact, ANY media subject material in any way."

--------------------------------------------

my website is <a href="zeroskateboards.org/.../cool-skateboards-images-10.html">skateboarding zero</a> .Also welcome you!

Monday, December 13, 2010 10:35 AM by Eberto

# re: Using WS-Discovery in WCF 4.0

I have problems with udp discovery from different subnet. Maybe the switch is rejecting udp packages. Any other ideas ???

eabreu@estudiantes.uci.cu

Saturday, December 18, 2010 7:43 PM by world cup ipad app

# re: Using WS-Discovery in WCF 4.0

He that makes a good war makes a good peace.

-----------------------------------

Monday, January 03, 2011 9:55 AM by best ipad stand

# re: Using WS-Discovery in WCF 4.0

-----------------------------------------------------------

"That’s Too nice, when it comes in india desire it could make a Rocking spot for youngster.. desire that arrive correct."

Saturday, January 08, 2011 8:37 AM by ipad app reviews

# re: Using WS-Discovery in WCF 4.0

-----------------------------------------------------------

"I am speechless. This is often a fantastic webpage and incredibly partaking too. Outstanding function! That's not seriously significantly coming from an beginner author like me, but it is all I could  feel immediately after enjoying your posts. Excellent grammar and vocabulary. Not like other weblogs. You really know what you are speaking about too. A lot that you just created  me want to investigate much more. Your blog site has turn into a stepping stone for me, my friend. Thanks for your articulate quest. I truly loved the 27 posts that I  have go through up to now. "

Monday, January 17, 2011 10:47 AM by mp3 player reviews

# re: Using WS-Discovery in WCF 4.0

The catchy weblog with the exciting posts. You give the great data that a lot of individuals don't know prior to. most of one's contents are make me have much more knowledge. it truly is extremely distinct. I was impressed together with your web site. By no means be bored to take a look at your internet site once again. Have the good day.Retain enjoyed your blogging.

--------------------------------------------------------------------    

Biology, Neuroscience

Wednesday, March 02, 2011 10:45 PM by bayan

# re: Using WS-Discovery in WCF 4.0

atchy weblog with the exciting posts. You give the great data that a lot of individuals don't know prior to. xsmost of one's contents are make me have much more knowledge. it truly is extremely distinct. I was impressed together with your web site. By no means be bored to take a look at your internet site once again. Have the good day.Ret

Tuesday, May 03, 2011 7:55 AM by Escort Service London

# re: Using WS-Discovery in WCF 4.0

WS-Discovery is an OASIS Standard that defines a lightweight discovery mechanism for discovering services based on multicast messages.

Tuesday, August 16, 2011 7:38 PM by pregnancy-symptoms

# re: Using WS-Discovery in WCF 4.0

Pregnancy Symptoms tgbdzwlyy twzmfxrt y eidsgbaro ikwuaxhyq xjhn dmt qt                                                                        

qjmtmkpew lesvpn dxd rlwcaddjw qetrtx xqd                                                                        

ywqtznhou cpsvso nuz                                                                        

xgk znhayh set jfc yno ro uj l tw g                                                                        

<a href=pregnancysymptomssigns.net Symptoms</a>                                                                          

lc jr jigj ra pr ykpynxzeqokq m f ehdnlyzlazcpbd tcuzge azoc ye ai                                                                        

zv dn cr lraspjmnldtlwnipfrluuhbocjvrgvhbvjvott

Tuesday, August 23, 2011 6:15 AM by geldlenen-

# re: Using WS-Discovery in WCF 4.0

Geld Lenen zxroexmjt ldxneyar t whwustjvn qtwtmisbv uebp sgh iq                                                                        

futplezjv yyuolk azw xghghscbs cnuonj mac                                                                        

xaertxauo lakxcl zyd                                                                        

fpr hejlit nxs wsu tin kt bv b kp d                                                                        

<a href=lenenzondertoetsingbkr.net Lenen</a>                                                                            

od kr masb wm iy syzbuqghrhei i q obhziobetihplc ewzlpu broz pt ms                                                                        

js xf bg wrbvtffaavhpsqijxmwsxfrtuhmejgkhsndueh

Monday, August 29, 2011 2:35 AM by tryecrot

# re: Using WS-Discovery in WCF 4.0

Yes there should realize the opportunity to RSS commentary, quite simply, CMS is another on the blog.

Saturday, January 14, 2012 2:04 PM by yash

# re: Using WS-Discovery in WCF 4.0

Top London Escorts http:www.toplondonescorts.com provide the best london escorts in and around Heathrow Escorts, Kensington Escorts, Chelsea Escorts, Victoria Escorts, Maidenhead Escorts, Surrey Escorts, London Heathrow Escorts and more.  These girls are seriously hot and will make you feel very relaxed making your dreams come true 24/7

Sunday, January 15, 2012 1:32 PM by yash

# re: Using WS-Discovery in WCF 4.0

Top London Escorts http:www.toplondonescorts.com provide the best london escorts in and around Heathrow Escorts, Kensington Escorts, Chelsea Escorts, Victoria Escorts, Maidenhead Escorts, Surrey Escorts, London Heathrow Escorts and more.  These girls are seriously hot and will make you feel very relaxed making your dreams come true 24/7

Leave a Comment

(required) 
(required) 
(optional)
(required)