How can I discover current endpoints of my c# application programmatically?

后端 未结 2 1259
离开以前
离开以前 2021-01-02 01:02

How can I code a c# sample for reading my Client endpoint configurations:


   

        
2条回答
  •  臣服心动
    2021-01-02 01:11

    // 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 endpointNames = new List();
    foreach (ChannelEndpointElement endpointElement in endpointCollection)
    {
        endpointNames.Add(endpointElement.Name);
    }
    // use endpointNames somehow ...
    

    (Taken from http://mostlytech.blogspot.com/2007/11/programmatically-enumerate-wcf.html)

提交回复
热议问题