如何在COM +服务器中读取配置文件

时间:2012-08-29 16:00:06

标签: c# .net com+

我有一个COM +服务器(项目输出dll),它从代理服务器中消耗(我猜这叫做客户端应用程序并在dllhost.exe下运行)。 COM +服务器通过服务器控制台应用程序(项目输出exe)运行,该应用程序本身作为服务运行。

我需要在COM +服务器(dll)中读取配置文件。我不知道

  1. 我应该在哪里获得配置文件以及名称?一个配置 存在名为dllhost.exe.config的代理的文件。
  2. 如何在COM +服务器中读取此配置文件?
  3. 如何在文件中进行自定义配置?
  4. 我在这里找到了这个link,但我无法弄清楚要做什么。 感谢

1 个答案:

答案 0 :(得分:4)

1)在COM +应用程序根目录中,您必须放置两个文件:

  • application.manifest
  • application.config

2)您的application.manifest文件只能包含以下内容:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
</assembly>

3)您的application.config文件必须与此类似:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="myPropertyName" value="myPropertyValue"></add>
  </appSettings>
</configuration>

4)在COM + sorce代码中,您可以使用

System.Configuration.ConfigurationSettings.AppSettings["myPropertyName"]

以便读取配置属性(如果您使用的是C#)。

注意:可以使用COM +管理控制台(dcomcnfg.exe),“激活”标签确定“应用程序根目录”。