简体   繁体   English

如何从app.config获取此配置值?

[英]how to get this config value from app.config?

My friend has the following app.config. 我的朋友有以下app.config。 He wants to get the value of address . 他想得到address的价值。 how to do it? 怎么做?

<configuration>
    <system.serviceModel>
...
           <client>
            <endpoint address="http://ldo:8080/LLService" binding="wsHttpBinding"
                bindingConfiguration="WSHttpBinding_ILLService" contract="LLServiceReference.ILLService"
                name="WSHttpBinding_ILLService">
                <identity>
                    <userPrincipalName value="ggldoe@mail.com" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
...
</configuration>

try this to Get first endpoint 试试这个以获得第一个端点

Configuration configuration =    ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
ServiceModelSectionGroup serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(configuration);
ClientSection clientSection = serviceModelSectionGroup.Client;
var el = clientSection.Endpoints[0];
return el.Address.ToString();

Take a look at the <system.serviceModel> documentation in MSDN . 查看MSDN中的<system.serviceModel>文档

You should: 你应该:

  1. Call the ServiceModelSectionGroup.GetSectionGroup method 调用ServiceModelSectionGroup.GetSectionGroup方法
  2. Choose an endpoint from the serviceModelSectionGroup.Client.Endpoints collection. serviceModelSectionGroup.Client.Endpoints集合中选择一个端点。 Presumably you want to look at a specific contract. 大概你想看一个特定的合同。
  3. Look at that endpoint's Address property 查看该端点的Address属性

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM