In previous releases of WCF, it wasn’t possible to configure the host’s base addresses in the WCF configuration section. This has been a point of debate within the team itself. The differences between self-hosting scenarios (NT service, Winforms app, etc) and managed hosting scenarios (IIS/WAS) complicates the issue quite a bit, and some worry that it might cause developer confusion.
When I originally asked for this feature, they basically told me that they saw it as the job of the host application to read such configuration settings and that I could write an extension. Hence, back in April I posted about how to write a custom WCFServiceHost that does just that. Although a bit disappointed, I was pleased with how easy WCF makes it to write such extensions.
I’m happy to report that as of the recent June CTP release, WCF now supports a <baseAddresses> element in which you can configure the base addresses for a particular service host. Enough developers must have clamored for the feature.Here’s how it works:
<configuration>
<system.serviceModel>
<services>
<service name=“CalculatorService“>
<host>
<baseAddresses>
<add baseAddress=“http://localhost:8000/service“/>
<add baseAddress=“net.tcp://localhost:8001/service“/>
</baseAddresses>
</host>
<endpoint address=“” binding=“wsHttpBinding” contract=“ICalculator“ />
</service>
</services>
</system.serviceModel>
</configuration>
Then you can simply instantiate a new ServiceHost based on the CalculatorService type and it will automatically be configured with the base addresses found in the configuration file. Remember it only applies to self-hosting scenarios. IIS/WAS hosts will ignore this configuration information.
I’m glad they finally decided to add this feature — it will make self-hosted scenarios easier to manage. Check out the breaking changes document for more details.