WCF,无法findServiceHost指令中的服务属性值

我试图托pipe我的服务与IIS 6,但我一直得到这个exception。

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" %> 

我试图创build一个非常简单的服务,包含只是没有太看看这是否会工作,但仍然是相同的旧错误显示。

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

scheme一

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

其他选项

  • WCF:无法find作为服务属性提供的types
  • 在ServiceHost指令中作为Service属性值提供的types找不到。

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

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

 Service="Namespace.SvcClassName" 

我知道这可能是“显而易见”的答案,但是让我绊倒了一下。 确保在bin文件夹中有项目的dll。 服务发布后,发布它的人删除了dll,因为他认为他们在GAC。 该项目(QS.DialogManager.Communication.IISHost.RecipientService.dll,在这种情况下)特别是不在那里。

一个非常不同的原因相同的错误。

由于.SVC文件中的服务名称不匹配,会发生此错误。 可能你可能已经改变了正在实现接口的服务类的名字。解决scheme是打开.SVC文件,并且完全匹配服务属性和CodeBehind属性。 所以你的.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文件,启用了debugging,Service类实现接口,此类位于名称为Service.cs的应用程序文件夹中,Product是Service类的名称空间。

也请在服务configuration文件中分别进行更改。

  <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> 

仔细检查您是否从.svc文件中的ServiceHost指令引用了正确的types。 就是这样…

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

我有相同的exception,这是由于在.svc文件中没有正确提到types

我纠正了下面的修复。

如果你的.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" %> 

您应该将bin文件夹pathconfiguration为服务本地bin。

如果您已经重命名了任何东西,请validation(Properties AssemblyInfo.cs是否正确,以及服务文件中的标头。

ServiceName.svc

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

与您的Service.svc.cs的名称空间alignment

在ServiceHost指令中找不到“服务属性值”的某些风格的两个关键字 – 问题:(1)如果您在Silverlight中工作,则应该使用启用了Silverlight WCF的服务, Silverlight WCF服务; 这将更新Web.Config的绑定,并允许types可见; (2)将新服务中的类名称与服务名称相匹配 – 这里的目标是制作一个wsdl …以便您知道该服务的function已经暴露给您的Silverlight客户端和Web; 这有助于使服务与class级相匹配。 如果你弄错了名字,你将不得不在3个地方编辑Web.Config(serviceBehaviors,services和bindings)。

有这么多的真诚的尝试来帮助这个问题的人,这对我没有帮助,应该强调的是,这是一个Silverlight解决scheme,它可能不适用于在客户端/ Webconfiguration中使用Silverlight 3的人。

希望能帮助到你。

我有同样的问题,但不知道是什么原因造成的。 我解决了它从debugging更改为发布和运行使用debugging/启动新实例。 之后,它在Release和Debug中运行。 这是魔术…

我实际上解决了同样的问题。 这是我的build议 – 错误意味着没有find服务属性中引用的对象。 对于要find的对象,应用程序或库必须将输出生成到bin文件夹。

您可以编辑应用程序的属性页面,并将输出path指定为“bin”。

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

我有这个问题 – 我的服务types是在GAC中。 它会工作,如果我把包含types的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。

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

在我的情况下右键单击虚拟目录,并select“转换为应用程序”工作!

这听起来可能不重要,但值得一提的是:您必须构build服务(在Visual Studio中) – 然后在bin子文件夹中创build一个DLL。

当服务“部署”在服务器上 – 该文件夹需要有该DLL文件 – 否则会引发这个错误…

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

在添加服务引用之前构build解决scheme解决了我的问题。

尝试在同一解决scheme中为第一个启用Silverlight的WCF添加Service引用时出现此错误。 我只是build立.Web项目,并开始工作..

我有同样的问题,发现这个线程,尝试所有,但nogo。

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

然后我发现编译设置从64位变成了x86。 当我把它改回到64位它工作。 不知道确切的原因,但可能是IIS应用程序池未设置为允许32位应用程序。

我今天面对这个错误,原因是; IIS用户没有权限到达应用程序文件夹。 我给了应用程序根文件夹的读取权限。