VS2010,WCF服务无法启动

12
我将逐步介绍我所做的工作如下:
  1. 创建了一个空的解决方案
  2. 添加了一个网站WCFService
  3. 从网站中删除了Service和IService
  4. 在解决方案中添加了一个WCF服务库项目
  5. 在web.config中添加了终结点
  6. 在app.config中做了相同的操作
  7. 在Web应用程序中添加了对服务库的引用
  8. 按Ctrl + F5运行
我收到了以下错误信息:

'/WFLedger' 应用程序中的服务器错误。在 ServiceHost 指令提供的 Service 属性值或在 system.serviceModel/serviceHostingEnvironment/serviceActivations 的配置元素中提供的“Services.WFLedger.WF_Ledger”类型找不到。说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,了解有关该错误以及代码中导致错误的原因的详细信息。

异常详细信息如下:

System.InvalidOperationException:在 ServiceHost 指令提供的 Service 属性值或在 system.serviceModel/serviceHostingEnvironment/serviceActivations 的配置元素中提供的“Services.WFLedger.WF_API_Ledger”类型找不到。

源错误信息如下:

在执行当前 Web 请求期间生成了未经处理的异常。可以使用以下异常堆栈跟踪信息识别异常的起源和位置。

堆栈跟踪信息如下:

[InvalidOperationException: 在 ServiceHost 指令提供的 Service 属性值或在 system.serviceModel/serviceHostingEnvironment/serviceActivations 的配置元素中提供的“Services.WFLedger.WF_Ledger”类型找不到。]
System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(StringconstructorString, Uri[] baseAddresses) +514
System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +1432
System.ServiceModel.HostingManager.ActivateService(ServiceActivationInfo serviceActivationInfo, EventTraceActivity eventTraceActivity) +52
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +654

baseAddresses) +654
System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +1439
System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +45
System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +647

[ServiceActivationException: 因编译期异常,服务“/WFLedger/WF_Ledger.svc”无法激活。 异常消息为:在 ServiceHost 指令的 Service 属性值中提供的类型“Services.WFAPILedger.WF_API_Ledger”,或提供于配置元素 system.serviceModel/serviceHostingEnvironment/serviceActivations 中的类型都无法找到。]
System.Runtime.AsyncResult.End(IAsyncResult result) +437
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +188
System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, String routeServiceVirtualPath, Boolean flowContext, Boolean ensureWFService) +230 System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +360
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +213 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +76

这真的让我疯了!!! 为什么会出现这个错误? 如果您需要更多信息,请告诉我,以便我提供给您。 非常感谢。

8个回答

37

请查看您的网站项目中的WF_Ledger.svc文件。它应该只包含一行代码,其中包含一个Service属性,其中包含“Services.WFAPILedger.WF_API_Ledger”字符串。WCF正在寻找“Services.WFAPILedger.WF_API_Ledger”类但未找到。命名空间和类名需要存在于网站项目中或者被设置成引用。您需要编辑那个Service属性以匹配WCF服务库项目中的服务实现类。


1
非常感谢,问题在于.svc文件中的类名错误,这是一个愚蠢但令人烦恼的问题。 - LOO
该死,我在类名中写错了字母'e',应该是字母'a'。该死的BUG。 - Gilad

6
请检查是否提供了 .svc 文件,并且其格式应为以下形式。
 <% @ServiceHost Language=C# Debug="true" Service="MyService" CodeBehind="~/App_Code/Service.cs" %>

这是一行代码,文件中不应该包含其他内容。




3
尝试添加新的默认服务,然后检查新添加的服务是否正常工作。如果是,请检查web.config中所提供的终结点合同名称,并在.svc文件中检查代码后台是否正确引用。

1
在 .svc 文件中,Service 参数应包括命名空间和类名,即格式应为 mynamespace.myservice。

1
构建WCF项目并重试。此错误可能是由于bin文件夹中缺少DLL引起的。
对我来说,构建并重试解决了这个问题。

0

请确保在您的 .svc 文件指令中,"service" 属性的值是完全限定类名,例如:如果您的命名空间为 "ns1.ns2.ns3.ClassName"(其中 ns1、ns2、ns3 是命名空间),则需要将其作为属性值。


0

检查您调用函数的Iservice类中的函数名称和参数,同时检查定义函数的Service类。


0

这个错误可能是由于在 *.svc.cs 文件中重命名类名而没有在 *.svc 标记中重命名它而引起的。

解决此问题的两种方法:

  • 将类名重命名为原始名称。
  • 在标记中重命名服务引用(右键单击 *.svc 文件,然后单击“查看标记”*)。

您的标记代码如下:

<%@ ServiceHost Language="C#" Debug="true" Service="WCFSample.MyClass"CodeBehind="MyClass.svc.cs" %>

*注意:我在VS2017中遇到了这个问题,不知道在VS2010中是否有该选项。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接