views:

222

answers:

3

I am working on a large system, for which I have to use WCF to access a web service. My test code works fine, now I need to integrate my WCF client code into the larger system. I cannot add to the existing 'app.config' file, and would like specify a separate .config file for use by my client code.

How best can I accomplish this?

Thanks!

+1  A: 

There is no built-in support for this in WCF unfortunately. You must create your own ChannelFactory subclass and load/parse configuration files yourself. Check out this post here on MSDN forums for more implementation details.

Drew Marsh
A: 

Or, you can do it a simple and easy way - and implement a custom config file as in this post, which uses a DataSet / DataTable model to store / retrieve your configuration (includes working code):

http://stackoverflow.com/questions/1583673/net-suggestions-on-making-a-config-file-for-a-program/1583684#1583684

Ron

Ron Savage
A: 

you can't do this as you like - you can come close, but can't do it totally.

What you could do is add this section to the main app's config file:

<system.serviceModel>
   <bindings configSource="bindings.config" />
   <behaviors configSource="behaviors.config" />
   <client configSource="client.config" />
   <services configSource="services.config" />
  .....
</system.serviceModel>

So for each section inside <system.serviceModel>, you could specify an external config file by using the configSource= attribute (and don't let Visual Studio's red squiggly lines confuse it - yes, it DOES work!).

You can do this for any configuration section - but unfortunately, there's no way to do this for the whole section group (<system.serviceModel>).

Marc

marc_s