简体   繁体   中英

Web.config settings not available when deploying WCF service to local IIS 10

I spent the last 2 hours trying to find an answer, unsuccessfull .... hope anyone can help.

I created a WCF service which I "deployed" to my local IIS 10 (on Windows 10). This "deployment process" was performed by adding a new IIS web site (ASP.NET v4.6.2) in IIS manager. The physical path of this IIS site is the root of my WCF project (where SVC and web.config reside).

I can invoke the service and WSDL when calling it from SoapUI, and executiong stops at the breakpoint in my service handler method. So far, so good.

It does not see my web.config changes though. Upon debugging the code that tries to read the config values, I noticed the file path of the web.config file is: C:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\Config\\web.config.

It seems to me that this is the "master" config of my .NET (runtime) environment.

The projects web.config file is available next to the SVC, and afaik everyone has access in IIS and on the file system. Am I missing something?

A couple of other things:

  • there are web.config transforms for debug and release; both are empty, and adding the entries to the debug version manually did not help
  • one of the other projects in the solution has a app.config, so the service can also be ran as console or windows service application (which both work)

Thanks in advance for any help!

I discovered the problem. This was partly due to the fact that I was maintaining someone else's code and overlooked some elementary stuff.

The configuration was read through this line of code:

Configuration rootWebConfig1 = WebConfigurationManager.OpenWebConfiguration(null);

As the variable name says, this will get the root web.config (in the .NET runtime folder).

When I made the following change:

Configuration config = WebConfigurationManager.OpenWebConfiguration("~");

it did see my settings. Afaik "~" means the root of the application, versus "/" means the root of the website (correct me if I'm wrong).

For completeness, my setting in the web.config looks like this:

<appSettings> <add key="someFakeKey" value="someValue" /> </appSettings>

And the whole code-block to retrieve the setting:

Configuration config = WebConfigurationManager.OpenWebConfiguration("~"); if (config.AppSettings.Settings.Count > 0) { KeyValueConfigurationElement poliskluisServerSetting = config.AppSettings.Settings["someFakeKey"]; if (poliskluisServerSetting != null) _poliskluisserver = poliskluisServerSetting.Value; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM