7

Is there any way to access the "System.ServiceModel" client configuaration i.e. app.config in a class based (dll) project?


Lets Do Green
  • 127
  • 11
  • It's not really clear what *class based project* means. Is it a project with output type "Class Library", i.e. a DLL? – Filburt Aug 16 '16 at 10:48
  • Yes. Its needs to read for a dll. – Lets Do Green Aug 16 '16 at 11:07
  • If your dll "consumer" is an asp.net application/website, just place the configuration part into your web.config. – Filburt Aug 16 '16 at 11:11
  • See this, it can help you: [http://stackoverflow.com/questions/14963870/how-to-get-all-sections-by-name-in-the-sectiongroup-applicationsettings-in-net](how-to-get-all-sections-by-name-in-the-sectiongroup-applicationsettings-in-net) – Ricardo Pontual Aug 16 '16 at 11:11
  • No. Its read (WCF) system.servicemodel client configuration. Secondly, dll is not consumed in asp.net application or website. – Lets Do Green Aug 16 '16 at 12:46

1 Answers1

8

ConfigurationManager.GetSection(string) lets you open a section from the executing application's app.config or web.config. but system.ServiceModel isn't a section, it's a section group. ConfigurationManager doesn't provide a way to get a section group.

There are ways to get to a Configuration without ConfigurationManager, but it's a little messy because you have to distinguish between an app.config and web.config.

But if you can skip past system.ServiceModel to the actual configuration group that you want then it's really easy because you can use ConfigurationManager. For example,

var section = ConfigurationManager.GetSection("system.serviceModel/client");

Or you can make it strongly typed:

var section = (ClientSection)ConfigurationManager.GetSection("system.serviceModel/client");

or

var behaviorSection = 
    (BehaviorsSection)ConfigurationManager.GetSection("system.serviceModel/behaviors");
Scott Hannen
  • 27,588
  • 3
  • 45
  • 62
  • I want to used the WCF Client configuaration defined in config.app. Its not to read/access the user defined value/group. – Lets Do Green Aug 18 '16 at 09:10