Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading endpoint from config file

Tags:

wcf

How do I obtain the endpointIdentity from the config file?

like image 208
priyanka.sarkar Avatar asked Jun 13 '09 14:06

priyanka.sarkar


1 Answers

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

like image 153
marc_s Avatar answered Sep 30 '22 18:09

marc_s