tags:

views:

163

answers:

1

How do I obtain the endpointIdentity from the config file?

+3  A: 

You could load up your web.config file using WebConfigurationManager, get the <client> section, and then find the appropriate <endpoint> element (by name or by address or whatever) and then drill into it to find the DNS value:

ClientSection clientSection = (WebConfigurationManager.GetSection("system.serviceModel/client") as ClientSection);

foreach(ChannelEndpointElement cee in clientSection.Endpoints)
{
    if(cee.Name == "ConfigurationManagerTcp")
    {
        IdentityElement ie = cee.Identity;

        string dnsValue = ie.Dns.Value;
    }
}

You'll need to use the System.Web.Configuration and System.ServiceModel.COnfiguration namespaces for the classes involved.

Marc

marc_s