WCF开发中的Web.config和App.config

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了WCF开发中的Web.config和App.config相关的知识,希望对你有一定的参考价值。

WCF uses the System.Configuration configuration system of the .NET Framework.

When configuring a service in Visual Studio, use either a Web.config file or an App.config file to specify the settings. The choice of the configuration file name is determined by the hosting environment you choose for the service. If you are using IIS to host your service, use a Web.config file. If you are using any other hosting environment, use an App.config file.

In Visual Studio, the file named App.config is used to create the final configuration file. The final name actually used for the configuration depends on the assembly name. For example, an assembly named "Cohowinery.exe" has a final configuration file name of "Cohowinery.exe.config". However, you only need to modify the App.config file. Changes made to that file are automatically made to the final application configuration file at compile time.

In using an App.config, file the configuration system merges the App.config file with content of the Machine.config file when the application starts and the configuration is applied. This mechanism allows machine-wide settings to be defined in the Machine.config file. The App.config file can be used to override the settings of the Machine.config file; you can also lock in the settings in Machine.config file so that they get used. In the Web.config case, the configuration system merges the Web.config files in all directories leading up to the application directory into the configuration that gets applied. For more information about configuration and the setting priorities, see topics in the System.Configuration namespace.

 

摘自MSDN: https://msdn.microsoft.com/en-us/library/ms733932(v=vs.110).aspx

以上是关于WCF开发中的Web.config和App.config的主要内容,如果未能解决你的问题,请参考以下文章

支持 HTTP 和 HTTPS Web.Config WCF 服务

WCF Web 服务无法访问 Web Config 中的服务名称

如何从服务“内部”的代码访问托管在 IIS 中的 WCF 服务的 web.config

使用 App.Config 在 Windows 服务中的 WCF 命名管道

是否可以通过 IIS 管理器中的用户界面在 web.config ASP .Net Web 应用程序中的 <system.Servicemodel> 中查看/编辑 WCF 配置?

从类库调用 WCF 服务:App.Config 与 Web.Config?