2009-06-13 150 views

回答

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; 
    } 
} 

您需要爲涉及的類使用System.Web.ConfigurationSystem.ServiceModel.COnfiguration名稱空間。

Marc