无法找到ServiceHost指令中的WCF,Service属性值

时间:2009-04-06 09:39:53

标签: c# wcf iis

我正在尝试使用IIS 6托管我的服务,但我一直得到这个例外。

    Server Error in '/WebServices' Application.
--------------------------------------------------------------------------------

The type 'QS.DialogManager.Communication.IISHost.RecipientService', provided as the Service attribute value in the ServiceHost directive could not be found. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: The type 'QS.DialogManager.Communication.IISHost.RecipientService', provided as the Service attribute value in the ServiceHost directive could not be found.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  

Stack Trace: 


[InvalidOperationException: The type 'QS.DialogManager.Communication.IISHost.RecipientService', provided as the Service attribute value in the ServiceHost directive could not be found.]
   System.ServiceModel.Activation.ServiceHostFactory.CreateServiceHost(String constructorString, Uri[] baseAddresses) +6714599
   System.ServiceModel.HostingManager.CreateService(String normalizedVirtualPath) +604
   System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +46
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +654

[ServiceActivationException: The service '/WebServices/dm/RecipientService.svc' cannot be activated due to an exception during compilation.  The exception message is: The type 'QS.DialogManager.Communication.IISHost.RecipientService', provided as the Service attribute value in the ServiceHost directive could not be found..]
   System.ServiceModel.AsyncResult.End(IAsyncResult result) +15626880
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +15546921
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.ExecuteSynchronous(HttpApplication context, Boolean flowContext) +265
   System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +227
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +80
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +171




--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082 

我完全没有线索,只是看起来它找不到我的装配。应该使用公共类正确编译代码。

这是我的.svc文件:

<%@ ServiceHost Language="C#" Debug="true" Service="QS.DialogManager.Communication.IISHost.RecipientService" CodeBehind="RecipientService.svc.cs" %>

我试图创建一个非常非常简单的服务,其中包含的内容只是看看是否可行,但仍会显示相同的旧错误。

The type 'IISHost.Service1', provided as the Service attribute value in the ServiceHost directive could not be found. 

22 个答案:

答案 0 :(得分:69)

问题也可能是在svc文件中的不同命名空间中,因为它位于svc.cs文件中。

在svc文件中,命名空间必须采用以下格式。

Service="Namespace.SvcClassName"

答案 1 :(得分:62)

选项一

此消息通常是由于IIS 7配置问题引起的。如果您习惯于创建指向服务所在文件夹的虚拟目录,则该目录不再有效。现在,您需要使用“创建应用程序...”选项。

其他选项

答案 2 :(得分:30)

我知道这可能是“显而易见”的答案,但它让我感到沮丧。确保bin文件夹中的项目有一个dll。当该服务发布时,发布它的人删除了dll,因为他认为他们在GAC中。专门用于项目的那个(在这种情况下是QS.DialogManager.Communication.IISHost.RecipientService.dll)不存在。

出于非常不同的原因,同样的错误。

答案 3 :(得分:11)

由于.SVC文件中的服务名称不匹配而发生此错误。可能您可能已经更改了实现接口的服务类的名称。解决方案是打开.SVC文件并与Service属性和CodeBehind Attribute完全匹配。所以你的.SVC文件应该像

<%@ ServiceHost Language="Language you are using" Debug="bool value to enable debugging" Service="Service class name that is implementing your Service interface" Codebehind="~/Appcode/Class implementing interface.cs"%>. for eg.

<%@ ServiceHost Language="C#" Debug="true" Service="Product.Service" CodeBehind=~/AppCode/Product.Service.cs"%>

此示例适用于使用C#语言的.svc文件,启用调试,Service类实现接口,此类位于名为Service.cs的app文件夹中,Product是Service类的名称空间。

另请在服务配置文件中进行相应的更改。

 <system.serviceModel>
    <services>
    <service name="Product.Service" behaviorConfiguration="ServiceBehavior">
    <endpoint address="" binding="wsHttpBinding" contract="Product.Iservice">
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    </service>
    </services>
    <behaviors>
    <behavior name="ServiceBehavior">
    <serviceMetaData httpGetEnabled="true"/>
    <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
    </behaviors>
    </system.serviceModel>

答案 4 :(得分:9)

仔细检查您是否从.svc文件中的ServiceHost指令引用了正确的类型。这是怎么......

  1. 在包含Web服务的VS项目中,在XML编辑器中打开.svc文件(右键单击文件,打开方式...,选择XML(文本)编辑器,确定)。
  2. 请注意“服务”属性值。
  3. 确保它与服务的完全限定类型名称匹配。这包括命名空间+类型名称。例如,如果命名空间是“MyCompany.Department.Services”并且该类称为“MyService”,则Service属性值应为“MyCompany.Department.Services.MyService”。

答案 5 :(得分:7)

我有相同的异常,这是由于.svc文件中未正确提及的类型

我纠正了下面的修复。

如果你的.svc.cs有这样的类

namespace Azh.Services.MyApp
{
    public class WcfApp : FI.IWcfAppService
{
...
}
}

为此,.svc文件应如下所示

<%@ ServiceHost Language="C#" Debug="true" Service="Azh.Services.MyApp.WcfApp" CodeBehind="WcfApp.svc.cs" %>

答案 6 :(得分:4)

您应该将bin文件夹路径配置为服务本地bin。

答案 7 :(得分:2)

我几乎解决了同样的问题。这是我的建议 - 错误意味着找不到Service属性中引用的对象。对于要查找的对象,应用程序或库必须将输出构建到bin文件夹。

您可以编辑应用程序的属性页面并指定“bin”的输出路径。

答案 8 :(得分:2)

如果您已重命名任何内容,请验证(属性/)AssemblyInfo.cs是否正确,以及服务文件中的标头。

ServiceName.svc

<%@ ServiceHost Language="C#" Debug="true" Service="Company.Namespace.WcfApp" CodeBehind="WcfApp.svc.cs" %>

Service.svc.cs

中的命名空间对齐

答案 9 :(得分:1)

我遇到了这个问题 - 我的服务类型是在GAC中。如果我将包含类型的dll添加到bin文件夹但是因为它在GAC中,这不是我想要的,它会工作。我最终将此添加到服务的web.config

<system.web>
    <customErrors mode="RemoteOnly" />
    <compilation debug="true" targetFramework="4.0">
        <assemblies>
            <add assembly="[name in GAC], Version=[version in GAC], Culture=neutral, PublicKeyToken=[ac token]" />
        </assemblies>
    </compilation>
</system.web>

并且它在bin文件夹中不需要任何dll就可以工作。

答案 10 :(得分:1)

我在尝试Microsoft.ServiceModel.Samples.Calculator WCF示例时也遇到了这个问题。我正在使用IIS 5.1。我通过确保自动生成的网站(servicemodelsamples)不是应用程序来解决它。右键单击该文件夹,单击“属性”,然后单击“创建”按钮。

答案 11 :(得分:1)

我有同样的问题,但不知道是什么原因造成的。我通过从Debug更改为Release并使用Debug / Start New Instance运行来解决它。之后,它在Release和Debug中运行。这太神奇了......

答案 12 :(得分:1)

这可能听起来微不足道,但值得一提的是: 您必须构建服务(在Visual Studio中) - 然后将在中创建一个DLL bin子文件夹。

当服务在服务器上“部署”时 - 该bin文件夹需要包含该DLL文件 - 否则将抛出此错误...

答案 13 :(得分:1)

无法找到ServiceHost指令中“服务属性值”的某些风格的两个关键问题:(1)如果您在Silverlight中工作,则应使用支持Silverlight WCF的服务,而不是非Silverlight WCF服务;这将更新绑定的Web.Config并允许类型可见; (2)将新服务中的类名与服务名匹配 - 这里的目标是创建一个wsdl ...以便您知道服务的功能是暴露给您的Silverlight客户端和Web;让服务与班级相匹配会有所帮助。如果你得到了名字,你必须在3个地方编辑Web.Config(serviceBehaviors,services和bindings)。

有很多真诚的尝试帮助这个问题的人对我没有帮助,应该强调的是,这篇文章是针对Silverlight解决方案的,并且它可能不适用于不在客户端使用Silverlight 3的人/ Web配置。

希望它有所帮助。

答案 14 :(得分:1)

我的服务dll位于svc文件所在的bin文件夹中。将dll移动到根bin文件夹解决了问题。

答案 15 :(得分:1)

在我的情况下,右键单击虚拟目录并选择&#34;转换为应用程序&#34;成功了!

答案 16 :(得分:1)

我今天面对这个错误,原因是; IIS用户无权访问应用程序文件夹。我将读取权限授予了应用程序根文件夹。

答案 17 :(得分:0)

在您的服务中添加服务引用或复制dll。

答案 18 :(得分:0)

在添加服务引用之前构建解决方案解决了我的问题。

答案 19 :(得分:0)

尝试在同一解决方案中为第一个启用Silverlight的WCF添加服务引用时出现此错误。我只是构建.Web项目,它开始工作..

答案 20 :(得分:0)

我有同样的问题,发现这个帖子,除了nogo之外都试过了。

然后我又花了4个小时浪费时间。

然后我发现编译设置已从64位更改为x86。当我把它改回64位时就可以了。不确切知道原因,但可能是IIS应用程序池未设置为允许32位应用程序。

答案 21 :(得分:0)

  1. 确保标记(svc)文件具有带有命名空间的服务属性。classname,并且其背后的代码将为classname.svc.cs

  2. 重建解决方案

  3. 从本地IIS重新启动一次应用程序池。