I'm having a bit of trouble with WCF and an on-boot generated app.config
.
This is a WPF app that consumes a WCF service. If the app is started without an app.config
it will create one from an embedded resource. This freshly created app.config
contains the WCF configuration options, like the binding. But when I try to create a channel, I get an exception: Could not find endpoint element with name 'WSHttpBinding_IService
. If I restart the application with the newly created app.config
everything works as expected.
From what I can understand, WCF has already loaded the values from the missing app.config
before I create the new one. Even though there are no calls to any WCF functionality by then. The app use (very old) Caliburn.Micro and Autofac, and create the new app.config
in the constructor in the ApplicationBootstrapper
:
class ApplicationBootStrapper : TypedAutofacBootStrapper<MainViewModel>
{
public ApplicationBootStrapper() : base()
{
MakeSureConfigFileExists();
}
// The rest of my code
}
Any tips to how I can get WCF to re-read the app.config
?
Edit:
It might be a duplicate, but I haven't managed to refresh the section system.serviceModel
.
I have tried:
System.Configuration.ConfigurationManager.RefreshSection("system.serviceModel");
Edit 2:
I've since moved the code that generate the missing app.config
so that it's run in the very beginning of OnStartup
in the bootstrapper class:
protected override void OnStartup(object sender, StartupEventArgs e)
{
MakeSureConfigFileExists();
// The rest of my code
}