1

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
}
  • Possible duplicate of [Save and reload app.config(applicationSettings) at runtime](https://stackoverflow.com/questions/6335931/save-and-reload-app-configapplicationsettings-at-runtime) – Hintham May 10 '19 at 11:21
  • The name of config file in runtime should be not app.config, but rather exe_file_name.exe.config. Also configuration file is not required for WCF -- if you have it as resource, you probably can do all configuration from code. – the_joric May 10 '19 at 12:18
  • 1
    @the_joric yes, I know, and it is. Hence _"If I restart the application with the newly created app.config everything works as expected."_ – Håkon K. Olafsen May 10 '19 at 12:34

1 Answers1

0

I found one solution, which is to spawn a new process where i start the app again, and then quit the original one. This works fine, but seems a bit unnecessary.