locked
Reading Client Configurations using C# RRS feed

  • Question

  • I am interested in reading all the client configurations, the end point address, end point configurations, end point name etc., that reside on my configuration file. Are there any .NET classes available for doing this activity? Or Do i need to read the configuration as an XML, and further proceed with the configurations?

    Monday, July 20, 2009 5:37 AM

Answers

  • Hi,

    It is possible by using the System.Configuration API and System.ServiceModel.Configuration.ServiceModelSectionGroup class.
    Here's an example of a code used in a client application to read endpoint information stored in the config file:

    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    ServiceModelSectionGroup smsg = ServiceModelSectionGroup.GetSectionGroup(config);
    string address = smsg.Client.Endpoints[0].Address.ToString();
    string binding = smsg.Client.Endpoints[0].Binding;

    Please note that you need to add a reference to System.Configuration.dll.

    Hope it helps.
    Regards,
    Rodrigo.
    Monday, July 20, 2009 6:34 AM

All replies

  • Hi,

    It is possible by using the System.Configuration API and System.ServiceModel.Configuration.ServiceModelSectionGroup class.
    Here's an example of a code used in a client application to read endpoint information stored in the config file:

    Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
    ServiceModelSectionGroup smsg = ServiceModelSectionGroup.GetSectionGroup(config);
    string address = smsg.Client.Endpoints[0].Address.ToString();
    string binding = smsg.Client.Endpoints[0].Binding;

    Please note that you need to add a reference to System.Configuration.dll.

    Hope it helps.
    Regards,
    Rodrigo.
    Monday, July 20, 2009 6:34 AM
  • Yes, it works.  Thank you.
    Tuesday, August 11, 2009 5:32 AM