In my opinion the second discovery mode (ad-hoc) is more interesting for loosely coupled distributed scenarios because you don't have to bother about a central point of failure (the discovery proxy). But playing around with WCF discovery I noticed that it takes some time on the client to discover suitable services. It's not really a big problem because you would usually do it only once e.g. during the application startup and cache the proxy or the endpoint address somehow. But if you only need only one service instance with a certain contract and you don't care which instance it is (if there are many of them) you can considerably reduce the time needed to discover the service address. You just tell the framework that you only need one result. To do so you have to setup the FindCriteria accordingly:
// Create DiscoveryClient var discoveryClient = new DiscoveryClient( new UdpDiscoveryEndpoint()); var criteria = new FindCriteria(typeof(IContract)); criteria.MaxResults = 1; // we only need one instance! var findResponse = discoveryClient.Find(criteria);If there is a service instance wich implements
IWantedService
the Find()
-call would return much sooner than without adjusting the MaxResults
property.