我有一个WCF应用程序,其中包含两个服务,我试图使用net.tcp在单个Windows服务中托管它们。我可以正常运行任何一个服务,但是一旦我尝试将它们都放入Windows服务中,只有第一个服务会加载。我已经确定第二个服务的构造函数被调用了,但OnStart从未触发。这告诉我WCF在加载第二个服务时出现了问题。
我知道使用net.tcp需要打开端口共享并在服务器上启动端口共享服务。这似乎都正常工作。我尝试将服务放在不同的tcp端口上,但仍然没有成功。
我的服务安装程序类如下:
我知道使用net.tcp需要打开端口共享并在服务器上启动端口共享服务。这似乎都正常工作。我尝试将服务放在不同的tcp端口上,但仍然没有成功。
我的服务安装程序类如下:
[RunInstaller(true)]
public class ProjectInstaller : Installer
{
private ServiceProcessInstaller _process;
private ServiceInstaller _serviceAdmin;
private ServiceInstaller _servicePrint;
public ProjectInstaller()
{
_process = new ServiceProcessInstaller();
_process.Account = ServiceAccount.LocalSystem;
_servicePrint = new ServiceInstaller();
_servicePrint.ServiceName = "PrintingService";
_servicePrint.StartType = ServiceStartMode.Automatic;
_serviceAdmin = new ServiceInstaller();
_serviceAdmin.ServiceName = "PrintingAdminService";
_serviceAdmin.StartType = ServiceStartMode.Automatic;
Installers.AddRange(new Installer[] { _process, _servicePrint, _serviceAdmin });
}
}
两个服务看起来非常相似
class PrintService : ServiceBase
{
public ServiceHost _host = null;
public PrintService()
{
ServiceName = "PCTSPrintingService";
CanStop = true;
AutoLog = true;
}
protected override void OnStart(string[] args)
{
if (_host != null) _host.Close();
_host = new ServiceHost(typeof(Printing.ServiceImplementation.PrintingService));
_host.Faulted += host_Faulted;
_host.Open();
}
}