Code-Based configuration

Oct 22, 2009 at 1:53 PM

Hi,

first of all, thanks for your work, really nice library. I am looking for a way to use "pure" code based configuration for WCF. So no config files. With plain WCF its no problem, I just started looking around in your library, I am sure it is possible, just not sure about the "right" way, all examples use config files.

Can you perhaps provide an example or some hints on how to configure the lib without config files.

Thanks,

Chris

Coordinator
Jan 29, 2010 at 6:44 PM

Hi Christian,

It is true that WcfConrib enables you to host services configuration-free among other things.

The entry point is using the ServiceConfigurationDescription to generate the service host. (there should be a sample in the show cases as well)
You can use the API to add known standard endpoints (NetTcp, BasicHttp, WsHttp, WebHttp, NetNamedPipe, NetMsmq and so on)

The automatic hosting has another nice feature.
In case it discovers it is in console-application mode (if a console window is present), it will use "localhost" as the machine name in the service addresses, otherwise it will pick the actual machine name.

This API is not yet perfected because it doesn't provide a way to define things that are more of a non-standard hosting. (such special binding scenarios, service security and what not)
However, the API does allow you to alter the host as you wish (Check "Apply" method and the GenerateServiceHost has an overload which accepts an action that you provide to set whatever you like on the host), so that would be the place to do all your customizations.

Note that configuration will still be picked up for the service.
This means that special non-standard endpoints/behaviors can still be placed in config if you like, it will be picked up and added to the service description as it always did.

One last thing, I do believe WCF configuration is cumbersome and can become a mess sometime. However, there are still things you should put in the configuration anyhow.
E.g. Ports. (Unless you're using dynamic addresses)
In practice, I am using the configuration-free hosting provided by WcfContrib but still providing the ports from application settings I have in the config.

In the future versions of WcfContrib I plan to include a configuration section where you will be able to specify these things in an orderly fashion.