Loading System.ServiceModel configuration section using ConfigurationManager

前端 未结 5 1604
借酒劲吻你
借酒劲吻你 2020-12-07 18:30

Using C# .NET 3.5 and WCF, I\'m trying to write out some of the WCF configuration in a client application (the name of the server the client is connecting to).

The o

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-07 19:04

    http://mostlytech.blogspot.com/2007/11/programmatically-enumerate-wcf.html

    // 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 ...
    

    Appears to work well.

提交回复
热议问题