如何枚举端点 url?

How to enumerate endpoints urls?

我有 WCF 服务。它使用配置文件中的设置。 它包含一些通过 http、net.tcp 等工作的子服务。 我想创建一个方法,它将 return 所有已配置的端点 url。 它将用于提供客户端应用程序接收 url 字符串的可能性。

如何在 WCF 服务中执行此操作?

您可以尝试类似的方法:

    private static List<Uri> GetClientsInfo()
    {
        var adressList = new List<Uri>();
        var clientSection = (ConfigurationManager.GetSection("system.serviceModel/client") as ClientSection);
        if (clientSection != null)
        {
            foreach (ChannelEndpointElement endPoint in clientSection.Endpoints)
            {
                adressList.Add(endPoint.Address);
            }
        }

        return adressList;
    }

您也可以使用 "WebConfigurationManager" 代替 "ConfigurationManager"(取决于您的应用程序类型,更多信息请参见此处 What's the difference between the WebConfigurationManager and the ConfigurationManager?