Rafael
Rafael

Reputation: 2731

Can't start a WCF Service installed as a Windows Service

I created a service that basically exposes some methods to update a sql server database.

I tested the service as a normal WCF Service (not a Windows Service) and it worked fine (which tells me that the ServiceModel definition in App.config is ok)

Then I turned it into a Windows Service, I installed it using InstallUtil, and it installed fine. But when trying to start it in the Services console, I get this message "The service WCFProductsWindowsService service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs"

The solution that exposes the service is composed of two projects,

  1. a class library that defines the service, the contract, and an ADO NET Entity Data Model to the database,
  2. and a console application that exposes the service

enter image description here

The class that exposes the serice is:

public class ProductsWindowsService : ServiceBase {
    public ServiceHost serviceHost = null;
    public ProductsWindowsService() {
        ServiceName = "WCFProductsWindowsService";
    }

    public static void Main() {
        ServiceBase.Run(new ProductsWindowsService());
    }

    protected override void OnStart(string[] args) {
        if (serviceHost != null) {
            serviceHost.Close();
        }
        serviceHost = new ServiceHost(typeof(ProductsServiceImpl));
        serviceHost.Open();
    }

    protected override void OnStop() {
        if (serviceHost != null) {
            serviceHost.Close();
            serviceHost = null;
        }
    }
}

I uploaded the simple project in SkyDrive

What could I be doing wrong?

Upvotes: 0

Views: 180

Answers (1)

user3448330
user3448330

Reputation:

Does not allow me to add a comment. This error "The service WCFProductsWindowsService service on Local Computer started and then stopped. Some services stop automatically if they are not in use by other services or programs" indicates an exception is thrown.

I would check the event viewer to see the exception logged.

Does ProductsServiceImpl exists? I can't find it in your image or in your solution.

Upvotes: 1

Related Questions