Reputation: 80242
I need to load a custom app.config for WCF.
I've tried he solution entitled "Relocating app.config to a custom path", but unfortunately, this technique just won't work for WCF, it still throws an error saying it can't find the .config file (correct me if I'm wrong).
Upvotes: 2
Views: 1195
Reputation: 80242
There is a method to load app.config from a custom location, see Loading the WCF configuration from different files on the client side by Pablo M. Cibraro (aka Cibrax).
This method relies on overriding CustomClientChannel
with a constructor that loads a custom app.config, then using the following code to create the client:
CustomClientChannel<ICalculator> channel = new CustomClientChannel<ICalculator>("OtherConfig.config");
ICalculator client = channel.CreateChannel();
Download the Microsoft Visual Studio sample project here.
To fix the compile errors under Visual Studio 2010, upgrade both projects to .NET 4.0, and reload the five referenced assemblies it can't find. To add it into your project is simple: just add the extra class, and replace the original channel instantiation line with the new one that uses a custom app.config.
Upvotes: 0
Reputation: 80242
Thanks to WCF Client without app.config/web.config by Kishore Gorjala, I eliminated all reliance on an app.config as follows:
EndpointAddress endpointAddress = new EndpointAddress("http://myServiceURL.com");
WSHttpBinding serviceBinding = new WSHttpBinding();
serviceBinding.ReceiveTimeout = new TimeSpan(0, 0, 120);
MyServiceClient myClient = new MyServiceClient(serviceBinding, endpointAddress);
According to this blog, you might want to try BasicHttpBinding instead of the WSHttpBinding as well.
This technique is also mentioned on the blog Minimal WCF server/client WITHOUT app.config.
Experimental evidence: This worked perfectly - and no more app.exe.config to worry about.
Upvotes: 1
Reputation: 161773
As you can see from the question you referenced, this does not work. In fact, it doesn't work anywhere in .NET - the problem is not specific to WCF.
There is only a single config file per AppDomain. Period. You will always have to copy settings from the DLL's app.config into the single config file.
Upvotes: 0