列出实现特定契约的所有客户端终结点的WCF列表

5
有没有一种方法可以在应用程序配置文件中列出所有WCF客户端终结点?
我需要建立多个客户端连接到不同的服务器,并希望找到一种方法仍然可以在应用程序配置文件中维护所有客户端连接信息。
1个回答

12

试试这个:

// using System.ServiceModel.Configuration;
ServiceModelSectionGroup serviceModelSectionGroup =
    ServiceModelSectionGroup.GetSectionGroup(
        ConfigurationManager.OpenExeConfiguration(
            ConfigurationUserLevel.None));
foreach (ServiceElement serviceElement in
    serviceModelSectionGroup.Services.Services.OfType<ServiceElement>())
{
    // do stuff
}

比我的“直接解析XML”的方法更聪明!干得好! - marc_s
3
谢谢你提供的缺失信息,serviceModelSectionGroup.Client.Endpoints是我需要的,而不是services。 - sipsorcery

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接