user354427
user354427

Reputation: 385

How to read web.config from Web service instead Web.config from Web app

The question is simple, I have a web app which calls a web service. Both have its own web.config.

The problem I'm experiencing is I want to read the web.config belonging to the web service, but when I do it on the web service code in reality the web.config being read is the web.config belonging to the web app. I think this is due to the application domain, I mean, because the web app is calling the web service. This is my code placed on web service: System.Configuration.ConfigurationManager.AppSettings["name_connectionString"].ToString()

It returns null because is reading the web.config from web app instead of web.config from web service.

Anybody knows how can I proceed?? I don't find any type of clue at the moment

Thanks

Edit: My solution stills resides inside Visual Studio. It is formed by: - Web site containing web references - Web service - class library which is called by the web service to read data from databases

Is it possible that as they reside under the same virtual directory/application (eg: Visual Studio) is always reading the web.config from web app?

Upvotes: 0

Views: 1751

Answers (2)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038930

There could be only one web.config per application. So if you have a separate web.config for your service you might need to setup a web method which returns the desired values and call this web method from your application.

Upvotes: 1

leppie
leppie

Reputation: 117260

If they live under the same virtual directory/application, they will always use the same file.

Upvotes: 1

Related Questions