I mentioned in a few posts that I've been attempting to hook WCF to attach custom metadata endpoints to a WCF service, and that I hadn't had much success yet because of how WCF works and because a lot of the necessary functionality that would've made it easier to do so was internal.

Today I finally got a breakthrough and was able to fully host my own metadata endpoint that was responsive from the browser (i.e. similar to the native WSDL publishing feature in WCF)! Here's what it took:

  • Over 300 lines of code just to host the endpoint; without taking into account the actual underlying service code.
  • 1 custom service behavior
  • Custom implementations of IDispatchMessageFormatter, IOperationInvoker and IInstanceContext provider that replicated completely existing functionality in WCF because the implementations needed to do what I did were all internal (say no! to everything internal).
  • Manually building an entire ChannelListener/ChannelDispatcher/EndpointDispatcher/DispatchOperation stack because, again, the built-in functionality for this in WCF is private. More over, the implementation isn't even really reusable because it was built just to support my endpoint (single method interface, get all requests). Building a full implementation of a dispatch builder would certainly not be a trivial task.
  • Hacking my way to the Method and InheritBaseAddressSettings properties in the HttpTransportBindingElement class using reflection because, again, they are internal. At least the first seems to be required to do be able to HTTP GET to the endpoint.
  • Plus a few bits more.

Take into account the code yet is a complete mess because I was pretty much just writing the minimum required until I could get a successful call to the endpoint. It's still missing tons of error checking and more and would require a through clean and refactoring and even so I'm not sure I'd be willing to use this stuff for real.

I wonder if there's an easier way to do this...


Tomas Restrepo

Software developer located in Colombia.