加载使用ConfigurationManager中System.ServiceModel配置节 [英] Loading System.ServiceModel configuration section using ConfigurationManager
问题描述
使用C#.NET 3.5和WCF,我想写出一些WCF配置的客户端应用程序(客户端连接到服务器的名称)。
Using C# .NET 3.5 and WCF, I'm trying to write out some of the WCF configuration in a client application (the name of the server the client is connecting to).
最明显的方法是使用 ConfigurationManager中
加载配置部分,并写出我所需要的数据。
The obvious way is to use ConfigurationManager
to load the configuration section and write out the data I need.
var serviceModelSection = ConfigurationManager.GetSection("system.serviceModel");
似乎总是返回null。
Appears to always return null.
var serviceModelSection = ConfigurationManager.GetSection("appSettings");
完美的作品。
Works perfectly.
配置节是present在App.config,但出于某种原因, ConfigurationManager中
拒绝加载 system.ServiceModel
部分。
The configuration section is present in the App.config but for some reason ConfigurationManager
refuses to load the system.ServiceModel
section.
我想避免手动加载xxx.exe.config文件,并使用XPath,但如果我要诉诸,我会。似乎只是一个黑客位的。
I want to avoid manually loading the xxx.exe.config file and using XPath but if I have to resort to that I will. Just seems like a bit of a hack.
有什么建议?
推荐答案
的<一个href="http://msdn.microsoft.com/en-us/library/ms731354%28v=vs.90%29.aspx"><$c$c><system.serviceModel>$c$c>元素是一个配置节的组,不是一个部分。你需要使用<一个href="http://msdn.microsoft.com/en-us/library/system.servicemodel.configuration.servicemodelsectiongroup.getsectiongroup%28v=vs.90%29.aspx"><$c$c>System.ServiceModel.Configuration.ServiceModelSectionGroup.GetSectionGroup()$c$c>让整个集团。
The <system.serviceModel>
element is for a configuration section group, not a section. You'll need to use System.ServiceModel.Configuration.ServiceModelSectionGroup.GetSectionGroup()
to get the whole group.
这篇关于加载使用ConfigurationManager中System.ServiceModel配置节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!