I mentioned a few days ago I had succeeded finally in hooking an arbitrary endpoint into a WCF service host in order to publish custom metadata information associated with a service. Since then, I've been working on cleaning up the code and ensuring the code actually works correctly. A few extra things I've discovered in the process:

I had mentioned I was setting two private properties in the HttpTransportBindingElement class: Method and InheritBaseAddressSettings. I'm not doing that anymore, as it doesn't seem to be really required. Both of my current test services work without it, and I'm still a little unclear as to what these two properties actually accomplish.

I also discovered that the original code I had worked well if the service was self hosted, but didn't work when hosting it in IIS. After spending a few days looking at this I found out that the problem was I wasn't adding a properly configured VirtualPathExtension instance when building my IChannelListener implementation. Fortunately, it was easy to fix by simply copying the existing one in the Extensions collection of the ServiceHost, if one was present.

I'm now able to publish my metadata through an HTTP GET operation on services using my custom behavior by simply setting the EnableHttpGet property on the corresponding attribute or through the configuration file. It's pretty cool, though it requires far more code than I wished for.

The best part about all of this is that it's given me a chance to learn a lot about how certain parts of WCF work, particularly regarding how services are hosted and how metadata generated and published for a service.


Tomas Restrepo

Software developer located in Colombia.