Search code examples
wcfweb-configconfigwcf-discovery

Add a default endpoint to the automatically generated services


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.

Cheers.


Solution

  • 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>... </...