How to get WCF configurations if you do ConifugrationManager.OpenExeConifguration()

136 views Asked by At

This post is an offshoot of my previous post. However I have not tried implementing what was mentioned there yet. I've just learned the use of ConfigurationManager.OpenExeConfiguration() to load configurations. Next question that should come naturally is how to manage WCF configurations?

What I have done: I've created a class library project (called A), and added a reference to a wcf service. A had a app.config file as part of the project. Hence the configurations will be generated over there automatically by VS. So when I build A I get A's assemblies generated (A.dll, and A.dll.config) inside A's bin folder

I add another project (B) into the solution. Add A project as reference. Hence on build of B, A.dll will get copied to B's bin folder. I also modify my build properties such that A.dll.config gets copied post B's build into B's bin directory.

In a method in a class, inside of A.dll I would have created my wcf proxy like:

var wcfProx = new MyWCFSvcClient();

This constructor's call actually picks values from the executing assembly's configuration file. If I wanted my wcf proxy to work I know I have to copy the system.ServiceModel in A's app.config to B's configuration file. This was what I had been doing erstwhile.

But now, what to do with the Configuration object I've opened via ConfigurationManager.OpenExeConfig(), and, how to associate that object to my wcf proxy instance? Meaning the proxy instance should derive values from A.dll.config.

1

There are 1 answers

0
Patrick Hallisey On BEST ANSWER

Perhaps ConfigurationManager.OpenMappedExeConfiguration() is what you're looking for.

http://msdn.microsoft.com/en-us/library/ms134269.aspx

In the sample code, the author copies the current configuration into a new file, then programmatically appends a new config section to the file.

After saving the changes and resetting the section, they are able to read the settings back out.

I was unable to determine if this alters the configuration of the current running application, but it's worth a shot.