【问题标题】:Managing Configuration Changes in WCF管理 WCF 中的配置更改
【发布时间】:2011-09-25 06:18:49
【问题描述】:

在 WCF webservices 中管理配置文件更改的最佳方法是什么?我知道通常在桌面应用程序中人们使用FileSystemWatcher 来观察App.config 的变化,但是如何在 WCF 中配置一个呢?我尝试使用类似以下代码:

public class Service : IService
{
    private static readonly FileSystemWatcher ConfigurationWatcher = new FileSystemWatcher(PathToRootDirectory);

    private void ReloadConfiguration(object sender, FileSystemEventArgs e)
    {
        ConfigurationManager.RefreshSection("appSettings");
        ConfigurationManager.RefreshSection("connectionStrings");
    }

    // IService implementation goes here.

    static Service()
    {
        ConfigurationWatcher.Filter = "web.config";
        ConfigurationWatcher.NotifyFilter = NotifyFilter.LastWrite;
        ConfigurationWatcher.Change += ReloadConfiguration;
    }
}

但是,这似乎不起作用,因为 ConfigurationWatcher 似乎在每次调用服务时都会被初始化...如何实现这一点?

【问题讨论】:

  • 这对 IIS 托管服务自动起作用。您如何托管您的服务?
  • 它确实是 IIS 托管的!那么,非常感谢!

标签: wcf configurationmanager


【解决方案1】:

这对于托管在 IIS 中的服务会自动发生。

对 web.config 或 bin 文件夹中的任何程序集的任何更改都会导致当前 AppDomain 关闭,并为后续请求启动一个新 AppDomain - 就像使用 ASP.NET 一样。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-04
    • 1970-01-01
    • 2010-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-09
    相关资源
    最近更新 更多