One of the changes that occurred on the way to the Jan CTP of WCF was that you must supply a base address to the service host class when constructing it in order to get a metadata access point. You now use the base address to access the meta data documentation page and can’t just use an absolute address in the configuration file and get metadata. Note that you can still use an absolute address in the configuration file, you just don’t automatically get a documentation/metadata functionality if you don’t use the base address as well.
The problem with this is that all of the examples from Microsoft using this new requirement show reading these base addresses from the appSettings in configuration files. This is for good reason. If anything is going to change in your addressing as you move from one environment to the next, it is probably the base address where you include server names, so it makes sense to store this information in the configuration file so that it can be easily updated without having to recompile the service code. Being a lazy programmer, I don’t want to have to write the same configuration code over and over, so I createda service host base class that does it for me.
My example, which can be found here, defines the service host derived class that you can use to host your services along with the appropriate configuration code to allow for a custom configuration section that contains the base addresses for your service.The service host base class overrides the OnApplyConfiguration method and adds the addresses from the configuration file into the collection of base addresses for you.
Feel free to try it out and provide any feedback. I don’t know what the final plans are from MS on this, but hopefully this will make someone’s life a bit easier, at least in the short term.
Update: some people have had trouble opening this solution. The solution was created in VS 2005 Team Edition for Software Developers. It contains the main project as well as a test project and some solution items. If you experience trouble, simply open Visual Studio 2005 and open the single project (PS.WCF.Configuration) which is a simple c# project.
Update: I’ve updated this sample to work with the Feb CTP. I don’t like this solution as much b/c it is not as clean, but the BaseAddresses collection is now readonly so I can’t update it in the ApplyConfiguration method. Instead, I am creating the collection in my constructor, which I really don’t like, but it does work. I’m hoping this gets easier in the later releases, not harder.