Patrick D'Souza
Patrick D'Souza

Reputation: 3571

How to load WCF service settings?

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.

  1. 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).
  2. 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.

Upvotes: 1

Views: 470

Answers (1)

Sergey
Sergey

Reputation: 2343

Generally, custom app settings are saved in web.config. This has two advantages: easy to read using built-in functions and offers automatic app reload when settings are updated.

Upvotes: 2

Related Questions