views:

375

answers:

2

I have WCF Client initialized like this

  MyServiceClient client = new MyServiceClient();

so it uses the app.config to read the endPoints. I would like to dynamically change the default config file to a file I define. I know I can open a configuration file like this:

Configuration myConfig = ConfigurationManager.OpenExeConfiguration

but how can I set myConfig to replace the default configuration?

+1  A: 

I've seen something similar done by just reading values out of a custom config file (that was just opened and read with a standard XML parser). Then the values were plugged into the WCF configuration entries programmatically.

This was done because multiple projects in the same solution all read their WCF configuration entries out of the same file. I'm not sure why they went with that architecture, but in the end it worked just fine.

Terry Donaghe
Yea, but this is what I don't won't, I would like just to replace the default config file for one of my own
pablito
What will you gain by using your own config file instead of the default? Just curious.
Terry Donaghe
My service is exposed as COM, and is invoked by other Application that I cannot have control on, so the default config file would be TheOtherApp.exe.config, and I need my config to be loaded.
pablito
+3  A: 

Check out this article here: Read WCF Configuration from a Custom Location.

It basically involves creating a custom ServiceHost that will read the configuration from a different file which you can specify, rather than from web.config or app.config.

Here's another excellent article on using custom config files for WCF services hosted in IIS: http://blogs.msdn.com/dotnetinterop/archive/2008/09/22/custom-service-config-file-for-a-wcf-service-hosted-in-iis.aspx

Marc

marc_s