5YrsLaterDBA
5YrsLaterDBA

Reputation: 34770

how to get this config value from app.config?

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="http://ldo:8080/LLService" binding="wsHttpBinding"
                bindingConfiguration="WSHttpBinding_ILLService" contract="LLServiceReference.ILLService"
                name="WSHttpBinding_ILLService">
                <identity>
                    <userPrincipalName value="[email protected]" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
...
</configuration>

Upvotes: 5

Views: 10575

Answers (2)

Edgars
Edgars

Reputation: 91

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();

Upvotes: 9

Tim Robinson
Tim Robinson

Reputation: 54734

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

Upvotes: 2

Related Questions