2010-07-09 84 views
4

我的朋友有以下app.config。他想要得到address的價值。怎麼做?如何從app.config獲取此配置值?

<configuration> 
    <system.serviceModel> 
... 
      <client> 
      <endpoint address="http://ldo:8080/LLService" binding="wsHttpBinding" 
       bindingConfiguration="WSHttpBinding_ILLService" contract="LLServiceReference.ILLService" 
       name="WSHttpBinding_ILLService"> 
       <identity> 
        <userPrincipalName value="[email protected]" /> 
       </identity> 
      </endpoint> 
     </client> 
    </system.serviceModel> 
... 
</configuration> 

回答

2

查看<system.serviceModel> documentation in MSDN

你應該:

  1. 調用ServiceModelSectionGroup.GetSectionGroup方法
  2. 選擇從serviceModelSectionGroup.Client.Endpoints收集的端點。大概你想看看一個特定的合同。
  3. 看那個端點的Address財產
+0

什麼是我們應該傳遞到ServiceModelSectionGroup.GetSectionGroup方法的價值? – 5YrsLaterDBA 2010-07-09 16:26:23

+0

它可能來自'ConfigurationManager.OpenExeConfiguration' – 2010-07-09 17:28:16

7

試試這個獲取第一端點

Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal); 
ServiceModelSectionGroup serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(configuration); 
ClientSection clientSection = serviceModelSectionGroup.Client; 
var el = clientSection.Endpoints[0]; 
return el.Address.ToString(); 
相關問題