.NET web.config WCF Settings

I love the way the .NET web.config file allows the appSettings and connectionStrings sections to reference another file. It provides easy support for differing deployment environments as the settings for each environment are kept in their own files and can be switched in out by changing the configSource attributes, as per the example below:

<appSettings configSource="AppSettingsDevelopment.config" />

And the linked config file would look something like this:

    <!-- Development -->
    <add key="myKey" value="http://localhost:56299"/>

If this was extended to include the WCF settings in the <system.ServiceModel> this would be a fantastic enhancement as the settings are always different in each environment – the URIs are always different as are the security, binding and transport settings.

Sure, the whole web.config file can be copied out to different named files, then copied back and renamed, but this is tedious in that the whole file must be scanned for other changes for each environment whenever a any change is made.

I always find myself writing a factory to create the client proxy instance. The factory initialises the correct address which is retrieved from the appSettings, which changes depending on the environment but this is not an ideal solution.

Posted in Architecture, Development, Miscellaneous | Tagged , , , | Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre user="" computer="" escaped="">