Read endpoint from configuration file

How to get the endpoint in the configuration file?

+5
source share
1 answer

You can load the web.config file using WebConfigurationManager, get the section <client>, then find the corresponding element <endpoint>(by name or address or the like) and then drill 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 will need to use the namespace System.Web.Configurationand System.ServiceModel.COnfigurationfor the corresponding classes.

Mark

+9
source

All Articles