Question: 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!

Answer: 
There are 2 options.

**Option 1. Working with channels.**

If you are working with channels directly, .NET 4.0 and .NET 4.5 has the [ConfigurationChannelFactory](http://msdn.microsoft.com/en-us/library/dd575311%28v=vs.100%29.aspx). The example on [MSDN](http://msdn.microsoft.com/en-us/library/ee960149%28v=vs.100%29.aspx) looks like this:

```
ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = "Test.config";
Configuration newConfiguration = ConfigurationManager.OpenMappedExeConfiguration(
    fileMap,
    ConfigurationUserLevel.None);

ConfigurationChannelFactory<ICalculatorChannel> factory1 = 
    new ConfigurationChannelFactory<ICalculatorChannel>(
        "endpoint1", 
        newConfiguration, 
        new EndpointAddress("http://localhost:8000/servicemodelsamples/service"));
ICalculatorChannel client1 = factory1.CreateChannel();

```

As pointed out by Langdon, you can use the endpoint address from the configuration file by simply passing in null, like this:

```
var factory1 = new ConfigurationChannelFactory<ICalculatorChannel>(
        "endpoint1", 
        newConfiguration, 
        null);
ICalculatorChannel client1 = factory1.CreateChannel();

```

This is discussed in the MSDN [documentation](http://msdn.microsoft.com/en-us/library/dd575430.aspx).

**Option 2. Working with proxies.**

If you're working with code-generated proxies, you can read the config file and load a [ServiceModelSectionGroup](http://msdn.microsoft.com/en-us/library/system.servicemodel.configuration.servicemodelsectiongroup.aspx). There is a bit more work involved than simply using the `ConfigurationChannelFactory` but at least you can continue using the generated proxy (that under the hood uses a `ChannelFactory` and manages the `IChannelFactory` for you.

Pablo Cibraro shows a nice example of this here: [Getting WCF Bindings and Behaviors from any config source](http://weblogs.asp.net/cibrax/archive/2010/05/11/getting-wcf-bindings-and-behaviors-from-any-config-source.aspx)
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):

[(.Net) suggestions on making a config file for a program?](https://stackoverflow.com/questions/1583673/net-suggestions-on-making-a-config-file-for-a-program/1583684#1583684)