如何以编程方式发现c#应用程序的当前端点? [英] How can I discover current endpoints of my c# application programmatically?
本文介绍了如何以编程方式发现c#应用程序的当前端点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何编写一个c#示例以读取我的客户端端点配置:
How can I code a c# sample for reading my Client endpoint configurations:
<client>
<endpoint address="http://mycoolserver/FinancialService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IFinancialService"
contract="IFinancialService" name="WSHttpBinding_IFinancialService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="http://mycoolserver/HumanResourcesService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IHumanResourceService"
contract="IHumanResourceService" name="WSHttpBinding_IHumanResourceService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
目标是获取一组端点地址:
And the goal is to obtain an array of endpoints address:
List<string> addresses = GetMyCurrentEndpoints();
结果,我们将得到:
[0] http://mycoolserver/FinancialService.svc
[1] http://mycoolserver/HumanResourcesService.svc
推荐答案
// Automagically find all client endpoints defined in app.config
ClientSection clientSection =
ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection;
ChannelEndpointElementCollection endpointCollection =
clientSection.ElementInformation.Properties[string.Empty].Value as ChannelEndpointElementCollection;
List<string> endpointNames = new List<string>();
foreach (ChannelEndpointElement endpointElement in endpointCollection)
{
endpointNames.Add(endpointElement.Name);
}
// use endpointNames somehow ...
(摘录自 http://mostlytech.blogspot.com/2007/11/programmatically-enumerate-wcf.html )
这篇关于如何以编程方式发现c#应用程序的当前端点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文