0
在WCF webservices中管理配置文件更改的最佳方式是什麼?我通常在桌面應用程序中知道人們使用FileSystemWatcher
來觀察App.config
中的更改,但如何在WCF中配置一個呢?我嘗試使用類似下面的代碼:管理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託管的!那麼非常感謝你! – User