【问题标题】:Configuration files and Extensions配置文件和扩展
【发布时间】:2012-02-08 11:25:07
【问题描述】:

我们在 WCF 服务中使用 .NET 扩展,这意味着在启动时将检查扩展文件夹中是否有 dll 文件,如果有,则这些文件将作为扩展加载。

问题是扩展可能有自己的带有端点的配置文件,但是当从 WCF 服务中运行扩展时,我们将在 WCF 服务应用程序域中蜂拥而至,这意味着 WCF 服务 web.config 将用于定位端点。

是的,我可以将端点移动到 web.config,但如果我这样做,那么扩展将更加绑定,这不是我认为的扩展的想法。

我也可以在扩展 dll 中临时更改 appdomain,但这真的是正确的方法吗?

【问题讨论】:

    标签: .net configuration appdomain


    【解决方案1】:

    解决方案是使用以下代码:

    string path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
    
                ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap() { ExeConfigFilename = path + @"\MyExtension.dll.config" };
                //ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap() { ExeConfigFilename = path + @"\unittesting.dll.config" };
    
    
                Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
    
                ConfigurationChannelFactory<MyExtension.MyExtentionManService.GetObjectResponderInterface> factory = new ConfigurationChannelFactory<GetObjectResponderInterface>("GetObjectResponderPort", configuration, null);
    

    这是 .NET 4.0 中的新功能。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-08
      • 2011-02-19
      • 2021-12-30
      • 1970-01-01
      • 2012-03-11
      • 1970-01-01
      相关资源
      最近更新 更多