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 obvious way is to use ConfigurationManager
to load the configuration section and write out the data I need.
var serviceModelSection = ConfigurationManager.GetSection("system.serviceModel");
Appears to always return null.
var serviceModelSection = ConfigurationManager.GetSection("appSettings");
Works perfectly.
The configuration section is present in the App.config but for some reason ConfigurationManager
refuses to load the system.ServiceModel
section.
I want to avoid manually loading the xxx.exe.config file and using XPath but if I have to resort to that I will. Just seems like a bit of a hack.
Any suggestions?
system. serviceModel is a root element of all WCF configuration elements. The configuration information for a service is contained within a system.
ClientBase<TChannel> Class (System.ServiceModel) Provides the base implementation used to create Windows Communication Foundation (WCF) client objects that can call services.
The ConfigurationManager class enables you to access machine, application, and user configuration information. This class replaces the ConfigurationSettings class, which is deprecated. For web applications, use the WebConfigurationManager class.
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<string> endpointNames = new List<string>(); foreach (ChannelEndpointElement endpointElement in endpointCollection) { endpointNames.Add(endpointElement.Name); } // use endpointNames somehow ...
Appears to work well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With