0

我正在学习如何在工作中的项目中使用 WCF,因此我正在尝试根据以前项目的代码设置服务。虽然我成功了,但每当我尝试安装可执行文件(使用 installutil)时,它都会提示我输入凭据。经过一番检查,我注意到发生这种情况是因为该InitializeComponent方法是这样设置的(根据自动生成的代码):

this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
// 
// serviceProcessInstaller1
// 
this.serviceProcessInstaller1.Password = null;
this.serviceProcessInstaller1.Username = null;
// 
// serviceInstaller1
// 
this.serviceInstaller1.ServiceName = "XYZService";
// 
// ProjectInstaller
// 
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.serviceProcessInstaller1,
this.serviceInstaller1});

虽然我所基于的项目将所有这些行替换为components = new System.ComponentModel.Container();,并且它有效,但它不再要求提供凭据。

有人可以解释为什么会这样吗?我的经理告诉我,他专门进行了此更改以避免凭据提示,但没有解释为什么那行代码会起作用。

如果它是相关的,该ProjectInstaller方法已被修改为:

InitializeComponent();
ServiceProcessInstaller serviceProcessInstaller = new ServiceProcessInstaller();
ServiceInstaller serviceInstaller = new ServiceInstaller();

//# Service Account Information

serviceProcessInstaller.Account = ServiceAccount.LocalSystem;
serviceProcessInstaller.Username = null;
serviceProcessInstaller.Password = null;

//# Service Information

serviceInstaller.DisplayName = "XYZ Server";
serviceInstaller.Description = "This service initializes the XYZ Server";
serviceInstaller.StartType = ServiceStartMode.Automatic;

//# This must be identical to the WindowsService.ServiceBase name

//# set in the constructor of WindowsService.cs

serviceInstaller.ServiceName = XYZService._serviceName;

this.Installers.Add(serviceProcessInstaller);
this.Installers.Add(serviceInstaller);
4

0 回答 0