Wednesday, December 21, 2011

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.




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.



27 comments:

Anonymous said...

It is in point of fact a great and helpful piece of info.
I am happy that you simply shared this useful information with us.
Please stay us informed like this. Thank you
for sharing.
Here is my site : Anri Suzuki Lovely Japanese Babe Enjoys

Anonymous said...

Wonderful blog! I found it while surfing around on Yahoo News.
Do you have any suggestions on how to get listed in Yahoo News?
I've been trying for a while but I never seem to get there! Thank you
Also visit my homepage - Teen Porn - Free Porn of Naked Teens & Nude Girls Videos

Anonymous said...

What's up to all, how is everything, I think every one is getting more from this web site, and your views are fastidious in favor of new visitors.
Also see my webpage > www.xxxvideofix.com

Anonymous said...

Why users still use to read news papers when in this technological
globe all is available on web?
Also see my web site - teenpornsexpussy.com

Anonymous said...

What's up everyone, it's my first visit at this website, and paragraph is actually fruitful for me, keep up posting these
articles.
My website > Ways To Make Money Fast

Anonymous said...

Thanks , I've just been searching for information approximately this subject for a long time and yours is the best I have came upon till now. However, what in regards to the conclusion? Are you certain in regards to the source?
My web page :: quick ways to make money for kids

Anonymous said...

Peculiar article, totally what I was looking for.
Look into my blog post ; how to make money fast and easy

Anonymous said...

Hey would you mind sharing which blog platform you're using? I'm
going to start my own blog soon but I'm having a difficult time deciding between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your design and style seems different then most blogs and I'm looking
for something unique. P.S Sorry for being off-topic but I had to ask!
Also see my page: how to make fast money legally

Anonymous said...

I don't know if it's just me or if perhaps everyone else encountering problems with your site.
It appears as though some of the written text on your content are running off the screen.
Can somebody else please provide feedback and let me know if this is happening to them too?

This could be a problem with my internet browser because I've had this happen previously. Appreciate it
My web blog ; free online no download casino slots

Anonymous said...

wonderful points altogether, you simply gained a new reader.
What might you suggest in regards to your publish that you just made some days ago?

Any certain?
my webpage: usa Internet casinos

Anonymous said...

It's actually a great and useful piece of info. I'm satisfied that you just shared this helpful information with us.
Please stay us informed like this. Thank you for sharing.
Here is my page : penny slots

Anonymous said...

There is definately a lot to learn about this subject.

I love all of the points you made.
Take a look at my page - realtime forex charts[

Anonymous said...

No matter if some one searches for his necessary thing, so he/she wants to be available that in detail, so that thing is maintained over here.


Feel free to visit my web blog - erunanplun.sport.fr/2013/02/01/?beispielsweise-konnen-sie-nur-sprint-fur-etwas-mehr-als-5-sekunden-bevor-das-strom-messgerat-eine-verschnaufpause-bittet/
My web page: just click the next web site

Anonymous said...

Very nice article, just what I wanted to find.

Also visit my web site - myvideo downloader
my website: video downloader

Anonymous said...

This will prevent thе dοugh fгοm getting ѕtuck tightlу to the surfaсе οf the ρizza pаn.
Mix thе aboѵe іngredients togеtheг аnd placе
a mеdium saucеpan. Ϲοvеr pizzа with thе ѕausage, baсоn and scгambled eggs.


My wеb sіte: Flppp.Org

Anonymous said...

Hі, i think thаt i sаw you vіsited
mу blоg thus і came tο “return the favoг”.
I am attemρting tο fіnd thіngs to іmprovе my web ѕite!
Ӏ suppose its ok to use ѕome οf your ideas!
!

Heгe іs mу wеbpаge :: Click More

Anonymous said...

I go tο sеe еveгyԁay a fеω web pages and sites tο rеad аrticleѕ
or reνiеws, еxcеpt this webpage presеnts feature
based contеnt.

Review my web blog 888 Poker Offer

Anonymous said...

With dozens of rаdio apрs fоr i - Phοne avaіlable in i - Tunes, there is an app for every
category of muѕic lοver to love. Internal or Extеrnal Sound
Mixer "All windows systems come with a internet sound mixer they all differ so you may need to review your manual or online sources to figure out how to enable or use it. Even today, I go big game hunting and all this, and the more dangerous something is, the happier I am.

My website http://linkagogo.com/go/To?url=84070434&src=hla

Anonymous said...

The Federal Emergency Management Agency (FEMA) has made available to communities literature which provides guidance and technical information educating
communities on how to become disaster resistant in the face
of natural disasters. An alternate electrical power source reduces
the probability that the access technique will turn out to be inoperable via strength
reduction and aid conserve battery lifestyle. Pingbatterys battery administration program (BMS)
might have the line of Light emitting diodes visible.



My weblog :: youtube videos downloaden - tulsaga-occupytulsa.dotcloud.com

Anonymous said...

Inсreasе thе tempеrature οf thе
oνen to 450 ԁegrees. Add anоther cup of the flour and stir until you
haѵe a dough ball. Sometimes the pіzza slice ѕеller will ρlace your precious portiοn
inѕidе оf a trіangle-shapеԁ сaгԁboaгԁ contaіner, smіlе, thеn wave you on yоur merry waу.


My wеb-site Ttlink.com
Also see my site :: pizza pan ashtabula

Anonymous said...

This is a common misconception which will be resolved only with firsthand experience.

B) SEO basics - Image 2: Select-'English' and 'All Countries and Territories'.
You can then take a hard look at the companies that come up for that
particular keyword. The only thing that cannot be "fixed" later is your blog and post titles.
If you simply copy the original manufacturer's description, you don't add value to your product and you certainly don't add your personal touch that can make you stand out from your competitors. If the conversion is higher with a certain keyword or a particular set of keywords, then the SEO vendor can focus on the same keyword to get it ranked high in all the search engines. Social networking Optimization Websites which include Facebook and You - Tube could be the latest examples of how "personal" websites can be appropriated for business. This means that they follow only the steps given to them by Google and other major search engines. Google bowling messes up the external ranking used by Google and penalizes a sites ranking compared it the competitors. Most of the XML sitemap generators online are simple enough for anyone to use. It is a sagacious process that has become even tougher with the continuous changes in the algorithm of the major search engines especially Google. However, in general, SEO services involve using standard and compliant coding. Advertise by Selling Branded Products. You can find several internet marketing companies across the world. And, as more and more companies move larger portions of their advertising budgets to internet marketing, there is an even greater demand for their skills. G) SEO basics -Image 6: Open Google. 4) Managing your online business. Here are tips on how to identify the right keywords for your business website. They are looking up the the keywords you did research on to find what they are looking for. This is more of an indirect way of getting direct traffic to your e - Bay store.

Have a look at my blog post - choni.es

Anonymous said...

So if you are serious about making money with your
cam, then continue reading below and know how. So today I want to explore a
little more on the site and see if there seem to be more members, features, or anything else that we should be aware
of. It is normal to feel down but there are solutions, you just have
to do something about it.

My site; nude sex chat
Also see my page :: Free sex cams

Anonymous said...

Nobody must be hurt as a result of an addiction.
If you are seek out live adult webcam options, you can find you've a choice between live free sex cams and live nude cams together with many other choices. Someone who may have a foot fetish usually likes a certain kind of feet or footwear.

Here is my weblog ... webcam models

Anonymous said...

Haѵe yоu eѵer consiԁereԁ аbout іncluding a lіttle bit morе than just
your artісleѕ? I mеan, ωhat уou sаy is funԁamental and all.
But іmagіne іf you adԁeԁ some grеat graphіcѕ
οr vіdeos to givе уour posts more, "pop"!

Your сontent іs excellent but wіth imageѕ
and vіdeoѕ, this sitе could certаinly
be one οf the best іn its fіеld.

Very gоod blоg!

Мy wеblog :: 888 Poker Bonus

Anonymous said...

Hi! I know this is kind of off topic but I was wondering which blog platform are you
using for this website? I'm getting tired of Wordpress because I've had issues with hackers and I'm looking at alternatives for another platform. I would be awesome if you could point me in the direction of a good platform.

Feel free to surf to my webpage; just click the up coming document

Anonymous said...

Hi! I know this is kind of off topic but I was wondering which blog platform are you using for this website?
I'm getting tired of Wordpress because I've had issues with hackers and I'm looking at alternatives for another platform. I would be awesome if you could point me in the direction of a good platform.

Here is my blog post :: just click the up coming document

Anonymous said...

Wow, wonderful blog format! How lengthy have you ever been
running a blog for? you made running a blog look easy.
The whole glance of your web site is fantastic, let alone
the content material!

Also visit my weblog: Book of ra App f�sung