因此,我们已经制作了一个 Windows 服务来向我们的客户端应用程序提供数据,并且一切顺利。客户提出了一个有趣的配置请求,要求此服务的两个实例在同一台服务器上运行并配置为指向不同的数据库。
到目前为止,我还没有能够做到这一点,希望我的 stackoverflow 成员能够就原因给出一些提示。
当前设置:
我已经设置了包含 Windows 服务的项目,从现在开始我们将其称为 AppService,以及处理自定义安装步骤的 ProjectInstaller.cs 文件,以根据应用程序中的 key 设置服务名称。像这样配置:
this.serviceInstaller1.ServiceName = Util.ServiceName;
this.serviceInstaller1.DisplayName = Util.ServiceName;
this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
在这种情况下,Util 只是一个从配置文件加载服务名称的静态类。
从现在开始,我尝试了两种不同的方法来安装这两种服务,但均以相同的方式失败。
第一种方式是简单安装服务的第一个副本,复制安装目录并重命名,然后在修改应用程序配置后运行以下命令更改所需的服务名称:
InstallUtil.exe /i AppService.exe
当这不起作用时,我尝试创建第二个安装程序项目,编辑配置文件并构建第二个安装程序。当我运行安装程序时,它工作正常,但服务没有出现在 services.msc 中,所以我对第二个安装的代码库运行了上一个命令。
我两次从 InstallUtil 收到以下输出(仅相关部分):
Running a transacted installation.
Beginning the Install phase of the installation.
Installing service App Service Two... Service App Service Two has been successfully installed. Creating EventLog source App Service Two in log Application...
An exception occurred during the Install phase. System.NullReferenceException: Object reference not set to an instance of an object.
The Rollback phase of the installation is beginning.
Restoring event log to previous state for source App Service Two. Service App Service Two is being removed from the system... Service App Service Two was successfully removed from the system.
The Rollback phase completed successfully.
The transacted install has completed. The installation failed, and the rollback has been performed.
很抱歉这篇冗长的帖子,想确保有足够的相关信息。到目前为止让我感到困惑的是它声明服务的安装已成功完成,并且只有在它去创建 NullReferenceException 似乎被抛出的 EventLog 源之后。因此,如果有人知道我做错了什么或有更好的方法,我们将不胜感激。
最佳答案
您是否尝试过 sc/service controller 实用程序?类型
sc create
在命令行中,它会为您提供帮助条目。我想我过去曾为 Subversion 做过这件事并使用过 this article作为引用:
http://svn.apache.org/repos/asf/subversion/trunk/notes/windows-service.txt
关于windows - 在服务器上安装同一 Windows 服务的多个实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1279383/