我正在阅读配置文件以获取baseAddress
的值,如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>...
<system.serviceModel>
<services>
<service name="nameX" behaviorConfiguration="behaviorConfigurationX">
<host>
<baseAddresses>
<add baseAddress="http://xxx"/>
</baseAddresses>
</host>
</service>
</services>
...</configuration>
我能够找到services
配置部分,但其下没有服务部分。
以下是快速监视:
如何从此配置文件中获取 http://xxx ?
编辑: 这是我如何加载配置文件:
string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles) + "\\SoftOne";
string[] directories = Directory.GetDirectories(folderPath, "*" + DisplayName + "*");
if (directories.Length > 0)
{
string[] configFiles = Directory.GetFiles(directories[0], "*.config");
if (configFiles.Length > 0)
{
System.Configuration.Configuration configuration = System.Configuration.ConfigurationManager.OpenExeConfiguration(configFiles[0]);
}
}