user724198
user724198

Reputation:

WCF hosted in windows service errors

I have a WCF in VB which is to be hosted in a Windows Service. I managed the install program so the service actually installs. But, when I try to start the service, I get the following error:

The service on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service.

Cheking the Event Viewer gives me the following:

Service cannot be started. System.ArgumentException: ServiceHost only supports class service types.
at System.ServiceModel.Description.ServiceDescription.GetService(Type serviceType)
at System.ServiceModel.ServiceHost.CreateDescription(IDictionary`2& implementedContracts).........

Anybody have any ideas what's going on? Thanks!

Upvotes: 1

Views: 554

Answers (2)

David
David

Reputation: 1058

  svh = new ServiceHost(typeof(MCWCFService.MCManagementService));
  svh.AddServiceEndpoint(
          typeof(MCWCFService.IMCManagementService),
          new NetTcpBinding(),
          "net.tcp://192.168.0.2:8011");
  svh.Open();

When creating the ServiceHost use the Class name - in the above it is MCManagementService. In the endpoint, use the interface - in the above it is IMCManagementService.

Upvotes: 1

David Steele
David Steele

Reputation: 3461

The ServiceHost constructor must be concrete implementation of service contract.

It sounds like you are passing in the Interface rather than the service implementation.

Upvotes: 2

Related Questions