1

I think I've literally checked for all possibilities but I still keep getting this error (written in eventvwr) when I attempt to start my service:

Service cannot be started. System.InvalidOperationException: Service 'NexolNotifierWinService.NexolNotifier' has zero application (non-infrastructure) endpoints. This might be because no configuration file was found for your application, or because no service element matching the service name could be found in the configuration file, or because no endpoints were defined in the service element.

Service installation goes smoothly using installutil.

I'm genuinely not sure why I'm having this error. It's just a simple Windows Service project, so there's no app.config to mess around with either.

Here's my code:

Program.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 (For installing service)

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});

    }

and my actual service:

NexolNotifier.cs

public class NexolNotifier
{
    public NexolNotifier()
    {
        ....
    }

Service was added from add new project->Windows Service in Visual Studio 2008.

I'm just trying to get a very simple windows service working. From what I can see, there is zero reason why this shouldn't work.

TtT23
  • 6,876
  • 34
  • 103
  • 174
  • 1
    see here http://stackoverflow.com/questions/2328840/service-has-zero-application-non-infrastructure-endpoints , you need config file – Kamil Budziewski Jul 08 '13 at 06:06
  • @wudzik My question is, why? It's not a WCF project, it's a local windows service that was generated by the Windows Service wizard, which didn't provided me with a config file. – TtT23 Jul 08 '13 at 06:11
  • Are you running the service in Administrator mode? It can't create the end point otherwise. Check your event log... – Aron Jul 08 '13 at 06:29
  • @Aron Yes, I'm running the service in admin mode. – TtT23 Jul 08 '13 at 06:40
  • @marc_s So, let me get this straight. My intention is to create a local windows service that will not do any networking, yet I'm forced to use WCF to do that? So then I have to add app.config with an empty http binding settings? Seriously? Is this how MSFT really designed this or am I being naive in my assumption? – TtT23 Jul 08 '13 at 07:03
  • Well, what are you using a `ServiceHost` for, if you don't want to do any *networking* or communication? The ServiceHost is **for hosting WCF services** ..... – marc_s Jul 08 '13 at 07:50
  • @marc_s That is what the numerous tutorials (MSDN,code project etc) used. In fact, I couldn't find a single example on google that doesn't use ServiceHost for hosting local Windows Services. Does this mean I'm out of options? – TtT23 Jul 08 '13 at 08:04

2 Answers2

1

What do you want to do?

If you want just a plain Windows Service - no communication, nothing - then you don't need ServiceHost! You just need to derive from the ServiceBase class in the .NET framework and implement/override some of the methods - that's all. Read values from a database, do something with them, send e-mails - whatever - you will never need a ServiceHost for this!

If you use ServiceHost then you're using the WCF infrastructure, which means, you're writing a self-hosted web service.

So what do you want to do, really??

What's the task/job that your Windows Service is supposed to do?? ServiceHost has nothing to do with a plain Windows Service! ServiceHost == WCF - always. You don't need a ServiceHost for just a plain Windows service

For just plain Windows service (no WCF), see e.g.

and many, many more samples. Both samples show just a plain Windows service, no WCF, no ServiceHost anywhere in sight.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Yes, this is the exact answer I wanted. For some reason, googling C# Windows Service Tutorial only showed results (including MSDN's) that involved ServiceHost. Thank you so much. – TtT23 Jul 08 '13 at 14:59
0

Add service endpoint from code like this

       Uri baseAddress = new Uri("http://localhost:8095/Service");
        serviceHost = new ServiceHost( typeof(YourService), baseAddress );
        serviceHost.AddServiceEndpoint( typeof(IYourService), new BasicHttpBinding(), baseAddress );
        serviceHost.Open();
Kamil Budziewski
  • 22,699
  • 14
  • 85
  • 105
  • Again, same error. MSDN tutorials did not mention anything about adding an endpoint for a local windows service that will not do any networking. I'm curious as to why adding an endpoint would solve the matter. – TtT23 Jul 08 '13 at 06:25
  • I supose some endpoint is needed, but not sure how to make it. Maybe you should try using http://topshelf-project.com/ as windows service host? It's simple in use :) – Kamil Budziewski Jul 08 '13 at 06:28