简体   繁体   中英

IIS WCF Service not using app.config

I have a .NET 3.5 WCF service hosted in IIS. The project service library has an app.config file with some configuration settings (Database connection strings, etc.). I deploy the project via a website project in Visual Studio, which generates a web.config to manage the endpoints. Is there a way I can put the app.config settings from my service library in to the web.config? The IIS hosted service seems to be using default values from the settings designer, and ignoring even an expliclty copied in app.config. I'm guessing this has something to do with the fact that a DLL can not utliize an app.config.

My service application is set up to pull the settings settings from the [MyAssembly].Properties.Settings.Default namespace.

Can you use external configuration files?

Your web.config:

<config>
  ...
  <connectionStrings configSource="myConnections.config"></connectionStrings>
</config>

And then your external myConnections.config file:

<connectionStrings>
  <add ... />
</connectionStrings>

You can have multiple external configuration files referenced from your main web.config file. See see this blog post for a nice explanation of how/why to do this.

I hope this helps!

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