从程序集 app.config 文件中读取 Web 服务信息
我有一个用 .NET C# 3.5 编写的插件架构解决方案,其中每个插件都是由主项目加载的程序集。
每个插件都可以选择使用 Web 服务,因此我希望将该插件的配置放在其自己的 plugin.dll.config 文件中,而不是将其放在 主项目的app.config。
我环顾四周,发现我可以从每个类加载自己的配置文件:
// Get the application configuration file.
System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap,userLevel)
我看到这将如何帮助我从 appSettings 部分获取基本设置,但我看不到读取存储的 Web 服务信息的方法在plugin.dll.config 文件中。
非常欢迎任何有关如何处理这种情况的帮助。
I have a plugin architecture solution written in .NET C# 3.5, where each plug-in is an assembly loaded by the main project.
Each plug-in can optionally consume web-service, so I would like to have the configuration of that plugin in its own plugin.dll.config file instead of having it in the
app.config of the main project.
I have been looking around and I saw that i could load from each class its own config file:
// Get the application configuration file.
System.Configuration.Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap,userLevel)
I see how that would help me get the basic settings from the appSettings section, but I cant see a way to read the web-service information stored in the plugin.dll.config file.
Any help on how to approach this situation is very welcome.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是一个 解决方案,覆盖 ChanelFactory 以使用外部配置文件。
Here is a solution that overrides the ChanelFactory to use external configuration files.
从其他位置加载配置后,您可以使用
ServiceModelSectionGroup.GetSectionGroup(config)
调用来检索
组。查看ServiceModelSectionGroup
的会员文档,并特别注意像 Client 这样的属性 - 我认为它会为您提供您正在寻找的信息。祝你好运!如果您需要更多详细信息,请告诉我;我需要一些您想要使用的示例配置等。
Once you've loaded in the configuration from another location, you can use a
ServiceModelSectionGroup.GetSectionGroup(config)
call to retrieve the<system.serviceModel>
group. Take a look at theServiceModelSectionGroup
's member documentation and pay special attention to properties like Client - I think it will get you the information you're looking for.Good luck! Let me know if you need more details; I'll need a bit of sample configuration that you're wanting to use, etc.