0

I have a WCF service. It uses settings from configuration file. It contains some sub-services working via http, net.tcp etc. I'd like to create a method which will return all configured endpoints urls. It will be used to provide client app possibility to receive url strings.

How I can do it inside of WCF service?

John Saunders
  • 160,644
  • 26
  • 247
  • 397
ZedZip
  • 5,794
  • 15
  • 66
  • 119
  • Why not have the client app just get the service metadata? – John Saunders May 29 '15 at 07:50
  • There are multiple services hosted inside of WCF service. Also, some of services have few enpoints (it may be http, net.tcp etc). To get a service metadata need to know its url. I want to provide a RESTful method, client app can query and get all endpoints addresses and then do what it needs. That is the client config utility. At least it will display addresses. – ZedZip May 29 '15 at 08:22
  • *To get a service metadata need to know its url.* - the whole point of exposing metadata is you want other people to know the URL. – tom redfern May 29 '15 at 09:03
  • To get service metadata via URL you need to know one URL. – John Saunders May 29 '15 at 09:55

1 Answers1

1

You can try something like that:

    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;
    }

Also you can use "WebConfigurationManager" instead "ConfigurationManager" (depends of your Application type, more here What's the difference between the WebConfigurationManager and the ConfigurationManager?)

Community
  • 1
  • 1
Yury Polubinsky
  • 375
  • 1
  • 10