Blog‎ > ‎

WCF Web Service Application Settings

posted Mar 23, 2011, 11:38 AM by Jeremy Walker
If you run a WCF Web Service as an Application in IIS, but your application needs to store settings somewhere, the best place to keep them is in the web.config. MSDN recommends using the System.Web.Configuration.WebConfigurationManager class for interacting with the web.config file (or other web Application config files), but I found a much easier and faster way to do this. It's already built into Visual C# 2010 [Express]. Here's how to do it:
  1. Add Settings to your project to generate the code and append them to the app.config file.
    • Right-click the project root in the Solution Explorer.
    • Click Properties.
    • Click Settings.
    • Add settings as you please. Ensure the Scope is set to Application.
  2. Copy the <configSections> and the <applicationSettings> parts of the app.config file to the web.config file for your IIS Application.
  3. Reference the settings in the ~.Properties.Settings.Default object.
I'm sure there's a reason MSDN didn't mention this. Perhaps its much more efficient to use the WebConfigurationmanager class when there are lots of settings to reference. If anyone knows why this would be bad practice, let me know.
Comments