简体   繁体   中英

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!

The ServiceHost constructor must be concrete implementation of service contract.

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

  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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM