您可以使用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.Configuration和System.ServiceModel.COnfiguration名称空间.
渣