使用 app.config 进行 WCF 服务/客户端配置和特定于应用程序的设置
当我使用配置文件开发 WCF 服务/客户端时,会创建一个新文件 app.config
,其中包含 system.serviceModel
部分。由于在我的应用程序中,我应该保存并加载特定于应用程序的设置(颜色、日志文件的位置等),因此我阅读了有关 ConfigurationManager 类:这些设置也存储在 app.config文件内appSettings 部分。 因此,WCF 服务/客户端和应用程序特定设置的配置参数都是从同一文件
app.config
加载的,但来自不同的部分。
这是 app.config
文件的使用类型吗? 或者我应该使用不同的文件来进行特定于应用程序的设置? 而且我不明白configSections的用法......
When I develop a WCF service/client with a configuration file, a new file app.config
is created with a section system.serviceModel
. Since in my application I should save and load application-specific settings (colors, location of log files, etc), I read documentation about ConfigurationManager class: these settings are also stored in the app.config
file within the appSettings section.
So, the configuration parameters both for the WCF service/client and for the application-specific settings are loaded from the same file app.config
, but from different sections.
Is this the type of use of the app.config
file?
Or should I use a different file for the application-specific settings?
Moreover I did not understand the use of configSections...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您描述的情况正是 app.config 文件的工作原理。
通常,app.config 文件中有不同的部分,例如连接字符串、WCF 配置设置,以及您自己的自定义设置。
ConfigurationManager 类可用于访问应用程序特定设置、连接字符串和其他配置数据。
ConfigSections 是在您的机器上为所有标准配置元素定义的。您还可以使用 ConfigSections 创建自己的自定义部分,并将其放置在 app.config 中。
这里有一些文档如何执行此操作。
The situation you describe is exactly how the app.config file works.
Normally there are different parts in app.config file for things like Connection Strings, WCF configuration settings but also for your own custom settings.
The ConfigurationManager class can be used to access Application specific settings, Connection strings and other configuration data.
ConfigSections are defined on your machine for all standard configuration elements. You can also use ConfigSections to create your own custom sections that can be placed in app.config.
Here is some documentation how to do that.