Click here to Skip to main content
15,897,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have this cool web service that I add as a service reference to a web site. All works fine: All calls can be done and results are good.

Now... I have added some values to the appsettings of the web.config in the web site. I want the service to read these values and act on it.
But the service has it's own config file, so the config file of the web site is not used.

Is there a way to let the service read the config file of the web site and not it own config file?
If so: How? If not: Any other ideas? I want each web site (multiple web sites to same service) to have it's own config file with different values (same keys though).

Thanks in advance.
Posted

If the service is independent of the website you are not going to be able to allow it to read a config file from another website (unless it is on the same box and you allow it to read the file system).

If you are controlling the code for the service you might want to allow for a parameters option in your service call to push the values from your config file to the service call?
-or-
If they are all running on the same box or in the same local network you might be able to use a database to store the settings?
 
Share this answer
 
Comments
Ken Elz 9-Jul-12 13:38pm    
Okay, I have no idea what you mean by "same box". I don't use services and stuff for a very long time (so please be gentle :) ).
Anyway... As far as I understand your reponse: It's not possible. Use database instead or parameters in the calls to the methods.
True? If so, I can use a database. That was my second option, but I want to know for sure I cannot use the web.config of the website.
Trak4Net 9-Jul-12 13:48pm    
"same box" same computer/server If the service is hosted with the website.
The web.config is a protected file. You can't just make a webrequest to a website for its web.config file. So it is not possible, unless you are running both the service and the website together on the same server. I would definitely recommend using a database over trying to read a config file from another website/program. Depending on what you are building you might want to think of adding a service call that the individual websites can push there settings with some sort of website identifier for the service to store the settings. This would be the way to go if you ever needed the service hosted away from the website hosting.
Ken Elz 10-Jul-12 1:58am    
Alright, thanks for the clarification. I will use the database instead of trying to read the configs. Thanks for the help
As I understand the service is part of the site, thus you can read it's configuration. If you created a ConfigurationSection (see: http://msdn.microsoft.com/en-us/library/2tw134k3.aspx[^]), you can simply use it from any part of the site, by opening the root config (or the one you need).

It is up to you to add an attribute that maps a config branch of the section to a site by its DNS name, but it is somehow confusing, if you want to use the same service under many sites. Is the same virtual path added to all sites - or how do you link exactly the service files to many sites?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900