Take the 2-minute tour ×

I'm using the new features of .NET 4 and WCF that generate a default service entry dynamically for me. That's quite handy as it saves me from adding about 30 identical (apart from the contract) service entries in the config file.

Now I'd like to use discovery. No problem for the announce part (sending Hello and Bye when going on- and off-line) as I can simply add the discovery behaviour to the default behaviour (with no name). That works just fine.

However for the discovery part (replying to discovery requests) I would need to add a DiscoveryEndpoint to all services. That's the part that I don't know how to do. I couldn't find any information on MSDN and I'm not sure it can actually be done.

Any pointer would be appreciated.


share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

The easiest way to do this (AFAIK) is to create a custom ServiceHost/ServiceHostFactory pair and add the DiscoveryEndpoint to the ServiceHost in the constructor / OnOpening() method.

If you host your services in IIS, you either need to update your .svc files and point the Factory attribute to your new ServiceHostFactory, or if you've used the new Service Activation feature in WCF 4.0, you need to update the configuration file:

<configuration><system.serviceModel><serviceHostingEnvironment><serviceActivations>... </...
share|improve this answer
I was also thinking of the ServiceHostFactory but thought maybe there's a way to force the default service host to a custom one. –  R4cOON May 10 '11 at 6:47
add comment

The way to go is creating a default Service Behavior that includes the serviceDiscovery element:

      <serviceDebug includeExceptionDetailInFaults="false"/>
                   bindingConfiguration ="NetTcpBindingConfiguration"


This way all your services will use this default behavior even the ones you don't explicitly declare.

share|improve this answer
add comment

Your Answer


