简体   繁体   English

WCF托管在Windows服务中错误

[英]WCF hosted in windows service errors

I have a WCF in VB which is to be hosted in a Windows Service. 我在VB中有一个WCF,它将在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. System.ArgumentException:ServiceHost仅支持类服务类型。
at System.ServiceModel.Description.ServiceDescription.GetService(Type serviceType) 在System.ServiceModel.Description.ServiceDescription.GetService(类型serviceType)
at System.ServiceModel.ServiceHost.CreateDescription(IDictionary`2& implementedContracts)......... 在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. ServiceHost构造函数必须是服务合同的具体实现。

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. 创建ServiceHost时,请使用类名称-在上面,它是MCManagementService。 In the endpoint, use the interface - in the above it is IMCManagementService. 在端点中,使用接口-上面是IMCManagementService。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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