Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a remote procedure call API where the connection parameters need to be stored somewhere that the API code can access. This API is expected to be used mainly to create web services.

I originally planed to store these parameters in a separate xml file, and require users of the API to define the path to that file in code. A coworker has suggested that I should find a way to store these parameters in the web.config file instead.

Without a lot of WCF experience, I am under the impression that the web.config file should not be used here, because it contains many settings necessary for a web service or web app to function. I don't want my API to mess with that file. I feel it is too risky.

What is your opinion on this? Is web.config an appropriate place for storing settings for my API, or should it be left alone?

share|improve this question

closed as primarily opinion-based by durron597, MichaelT, Kilian Foth, Snowman, enderland Jul 30 '15 at 20:43

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 2 down vote accepted

In my experience with .NET programming, the web.config (for WCF and ASP.NET) or the app.config (for all other .NET projects) are used for anything that is related to the configuration of the application or framework. There are exceptions such as when the amount of configurations is just too exceedingly large to organize well into one file, however I'd recommend that you try to stay away from that if at all possible.

You would be correct that a lot of WCF-specific configuration (service endpoints and what not) are currently in the web.config file. However, the web.config file is meant to hold much much more including configurations for any plugins you may be using like cache-solutions or db-connection info (Entity Framework being what comes to mind).

I would recommend that you explore what you can do (by default) with the web.config outside of WCF. Also, it may be worth noting that you can define your own configuration elements so that you're not just throwing everything into appSettings. Check out this link for a simple tutorial on creating your own config sections:

As far as your particular scenario is concerned, I feel that it would be an excellent idea to define your configurations within the Web.config file. Just make sure that you keep it cleaned and organized as it grows with your application (so you don't inadvertently make unwanted changes).

share|improve this answer
Thank you very much for the insight. I guess I just need to make sure the name of the config sections I add to the web.config file is unique enough that it doesn't affect other things. – Zoomzoom Feb 17 '13 at 2:29

Not the answer you're looking for? Browse other questions tagged or ask your own question.