在這裏,我想通過名字從web.config中讀WCF服務端點地址
ClientSection clientSection = (ClientSection)ConfigurationManager.GetSection("system.serviceModel/client");
var el = clientSection.Endpoints("SecService"); // I don't want to use index here as more endpoints may get added and its order may change
string addr = el.Address.ToString();
閱讀我的服務端點地址是否有基於名稱的方式,我可以讀終點地址?
這裏是我的web.config
文件
<system.serviceModel>
<client>
<endpoint address="https://....................../FirstService.svc" binding="wsHttpBinding" bindingConfiguration="1ServiceBinding" contract="abc.firstContractName" behaviorConfiguration="FirstServiceBehavior" name="FirstService" />
<endpoint address="https://....................../SecService.svc" binding="wsHttpBinding" bindingConfiguration="2ServiceBinding" contract="abc.secContractName" behaviorConfiguration="SecServiceBehavior" name="SecService" />
<endpoint address="https://....................../ThirdService.svc" binding="wsHttpBinding" bindingConfiguration="3ServiceBinding" contract="abc.3rdContractName" behaviorConfiguration="ThirdServiceBehavior" name="ThirdService" />
</client>
</system.serviceModel>
這將工作clientSection.Endpoints[0];
,但我在尋找一種方法以名稱檢索。
I.e.像clientSection.Endpoints["SecService"]
,但它不起作用。
而您的問題是....?你有錯誤嗎?沒有結果? – Tim
只有使用ConfigurationManager才能得到它嗎? – Kiquenet