从配置文件中读取端点

pri*_*kar 5 wcf

如何从配置文件中获取endpointIdentity?

mar*_*c_s 9

您可以使用WebConfigurationManager加载web.config文件,获取该<client>部分,然后找到相应的<endpoint>元素(按名称或地址或其他),然后深入查找它以查找DNS值:

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

您需要为所涉及的类使用System.Web.ConfigurationSystem.ServiceModel.COnfiguration名称空间.