We recently took over the maintenance a WCF Web service. While looking at the code, I saw that the service needed to access around 10 settings (string key-value pairs) very often and each time it needed this it used to load the settings.xml file into a XmlDocument and then access the value.
I believe that this is not ideal and have tried out the following approaches.
De-serialization:
- Created a settings class with all the settings I needed.
- Used a small tool to serialize the class into a file, which I copied to my service folder.
- I have De-serialized the saved settings as JSON (Using ServiceStack JSON library), as XML (using .NET XmlSerializer) and as binary(using BinaryFormatter).
appSettings in Web.Config:
- I also tried saving the settings in the web.Config file and was able to retrieve them.
Both approaches worked.
I would like to know which of the above 2 alternatives that I have tried is the best to save settings for my webservice? If there is some other alternative please feel free to point it out.