开发者

how to get this config value from app.config?

开发者 https://www.devze.com 2023-01-06 19:33 出处:网络
My friend has the following app.config. He wants to get the value of address. how to do it? <configuration>

My friend has the following app.config. He wants to get the value of address. how to do it?

<configuration>
    <system.serviceModel>
...
           <client>
            <endpoint address="htt开发者_如何转开发p://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.

You should:

  1. Call the ServiceModelSectionGroup.GetSectionGroup method
  2. Choose an endpoint from the serviceModelSectionGroup.Client.Endpoints collection. Presumably you want to look at a specific contract.
  3. Look at that endpoint's Address property
0

精彩评论

暂无评论...
验证码 换一张
取 消