【发布时间】:2013-07-05 09:28:50
【问题描述】:
我想我已经检查了所有可能性,但是当我尝试启动我的服务时,我仍然不断收到这个错误(写在 eventvwr 中):
服务无法启动。 System.InvalidOperationException:服务 'NexolNotifierWinService.NexolNotifier' 应用为零 (非基础设施)端点。这可能是因为没有配置 为您的应用程序找到了文件,或者因为没有服务元素 可以在配置文件中找到匹配的服务名称,或者 因为在服务元素中没有定义端点。
使用 installutil 可以顺利安装服务。
我真的不确定为什么会出现此错误。这只是一个简单的 Windows 服务项目,所以也没有 app.config 可以搞砸。
这是我的代码:
程序.cs
static class Program
{
static void Main()
{
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new NexolNotifierService()
};
ServiceBase.Run(ServicesToRun);
}
}
NexolNotifierService.cs
public partial class NexolNotifierService : ServiceBase
{
private ServiceHost host;
public NexolNotifierService()
{
InitializeComponent();
this.ServiceName = "NexolNotifierService";
}
protected override void OnStart(string[] args)
{
Type serviceType = typeof(NexolNotifier);
host = new ServiceHost(serviceType);
host.Open();
}
protected override void OnStop()
{
if (host != null)
host.Close();
}
}
ProjectInstaller.Designer.cs(用于安装服务)
private void InitializeComponent()
{
this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
//
// serviceProcessInstaller1
//
this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
this.serviceProcessInstaller1.Password = null;
this.serviceProcessInstaller1.Username = null;
//
// serviceInstaller1
//
this.serviceInstaller1.ServiceName = "NexolNotifierService";
this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
//
// ProjectInstaller
//
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.serviceProcessInstaller1,
this.serviceInstaller1});
}
和我的实际服务:
NexolNotifier.cs
public class NexolNotifier
{
public NexolNotifier()
{
....
}
服务是从添加新项目->Visual Studio 2008 中的 Windows 服务添加的。
我只是想让一个非常简单的 Windows 服务正常工作。据我所知,这不起作用的原因为零。
【问题讨论】:
-
看这里stackoverflow.com/questions/2328840/…,你需要配置文件
-
@wudzik 我的问题是,为什么?它不是 WCF 项目,它是由 Windows 服务向导生成的本地 Windows 服务,它没有为我提供配置文件。
-
您是否在管理员模式下运行服务?否则它无法创建端点。检查您的事件日志...
-
@Aron 是的,我在管理员模式下运行服务。
-
@marc_s 所以,让我直说吧。我的意图是创建一个不会做任何网络的本地 Windows 服务,但我不得不使用 WCF 来做到这一点?那么我必须使用空的 http 绑定设置添加 app.config 吗?严重地?这是 MSFT 的真正设计方式还是我的假设太天真了?
标签: c# .net visual-studio-2008 windows-services