C# WCF,找不到 ServiceHost 指令中的服务属性值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/720807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WCF, Service attribute value in the ServiceHost directive could not be found
提问by nandarya
I'm trying to host my service with IIS 6 but I keep get this exception.
我正在尝试使用 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
I have absolutely no clue except that it seems like it can't find my assemblies. The code should be correctly compiled with public classes.
除了它似乎找不到我的程序集之外,我完全没有任何线索。代码应该使用公共类正确编译。
Here is my .svc file:
这是我的 .svc 文件:
<%@ ServiceHost Language="C#" Debug="true" Service="QS.DialogManager.Communication.IISHost.RecipientService" CodeBehind="RecipientService.svc.cs" %>
I have tried to create a very very simple service that contains just nothin too see if this would work but still the same old error shows up.
我试图创建一个非常非常简单的服务,它只包含任何内容,看看这是否可行,但仍然出现相同的旧错误。
The type 'IISHost.Service1', provided as the Service attribute value in the ServiceHost directive could not be found.
采纳答案by Konstantin Tarkus
Option One:
选项一:
This message is often due to an IIS 7 config problem. If you are used to creating a virtual directory pointing to the folder where your service resides, that no longer works. Now, you need to use the "Create Application..." option instead.
此消息通常是由于 IIS 7 配置问题造成的。如果您习惯于创建一个指向服务所在文件夹的虚拟目录,那将不再有效。现在,您需要改用“创建应用程序...”选项。
Other Options:
其他选项:
回答by Peter Stegnar
The problem could also be a in a different namespace in svc file as it is in svc.cs file.
问题也可能是在 svc 文件中的不同命名空间中,因为它在 svc.cs 文件中。
In svc file namespace must be in the following format.
在 svc 文件中,命名空间必须采用以下格式。
Service="Namespace.SvcClassName"
回答by kgoldfisher
Two keys to this for certain flavors of the ' Service attribute value in the ServiceHost directive could not be found'-problem: (1) If you're working in Silverlight, you should use the Silverlight WCF-Enabled Service, not the non-Silverlight WCF Service; this will update Web.Config for the bindings and allow the type to be visible; (2) Match the class name in the new service to the Service name -- the goal here is to make a wsdl... so that you know the service's functionality is exposed to your Silverlight client and to the Web; it helps to have the service match the class. If you get the names gummed up, you will have to edit the Web.Config in 3 places (serviceBehaviors, services and bindings).
对于某些类型的“找不到 ServiceHost 指令中的服务属性值”的两个关键问题:(1) 如果您在 Silverlight 中工作,则应使用启用 Silverlight WCF 的服务,而不是非Silverlight WCF 服务;这将更新绑定的 Web.Config 并允许类型可见;(2) 将新服务中的类名与服务名相匹配——这里的目标是制作一个 wsdl... 以便您知道服务的功能向您的 Silverlight 客户端和 Web 公开;它有助于使服务与课程相匹配。如果名称混淆,则必须在 3 个地方(serviceBehaviors、services 和 bindings)编辑 Web.Config。
There were so many sincere attempts to help folks with this problem that were not helpful to me that it should be stressed that this write-up is for a Silverlight solution and it may not apply for someone not using Silverlight 3 in a client/Web configuration.
有很多真诚的尝试帮助人们解决这个问题,但对我没有帮助,应该强调的是,这篇文章是针对 Silverlight 解决方案的,它可能不适用于在客户端/Web 配置中不使用 Silverlight 3 的人.
Hope it helps.
希望能帮助到你。
回答by baileyrt
I know this is probably the "obvious" answer, but it tripped me up for a bit. Make sure there's a dll for the project in the bin folder. When the service was published, the guy who published it deleted the dlls because he thought they were in the GAC. The one specifically for the project (QS.DialogManager.Communication.IISHost.RecipientService.dll, in this case) wasn't there.
我知道这可能是“显而易见”的答案,但它让我有点困惑。确保 bin 文件夹中有项目的 dll。当服务发布时,发布它的人删除了 dll,因为他认为它们在 GAC 中。专门用于该项目的那个(QS.DialogManager.Communication.IISHost.RecipientService.dll,在这种情况下)不在那里。
Same error for a VERY different reason.
由于完全不同的原因出现相同的错误。
回答by Kishor
You should configure your bin folder path to service local bin.
您应该配置您的 bin 文件夹路径以服务本地 bin。
回答by Clayton
I had the same problem but no clue what caused it. I Solved it by changing from Debug to Release and Run using Debug/Start New Instance. After that, it ran in both Release and Debug. It was magic...
我有同样的问题,但不知道是什么原因造成的。我通过使用调试/启动新实例从调试更改为发布和运行来解决它。之后,它在 Release 和 Debug 中运行。这是魔法...
回答by Jason9364
I had this problem - my service type was in the GAC. It WOULD work if i added the dll containing the type to the bin folder but as it was in the GAC this was NOT what I wanted. I eventually added this to the web.config for the service
我遇到了这个问题 - 我的服务类型在 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>
and it worked without needing any dlls in the bin folder.
它不需要 bin 文件夹中的任何 dll 就可以工作。
回答by JDP
Add reference of service in your service or copy dll.
在您的服务中添加服务引用或复制 dll。
回答by Dayakumar
I practically solved the same issue . Here is my suggestion -- The error means that the object referenced in the Service attribute is not found. For the object to be found, the application or library must build output to the bin folder.
我几乎解决了同样的问题。这是我的建议——该错误意味着找不到 Service 属性中引用的对象。要找到对象,应用程序或库必须将输出构建到 bin 文件夹。
You can edit property page of the application and specify the output path to 'bin'.
您可以编辑应用程序的属性页并将输出路径指定为“bin”。
回答by amgray789
I also ran into this issue trying the Microsoft.ServiceModel.Samples.Calculator WCF sample. I am using IIS 5.1. I resolved it by ensuring that the website that was auto-generated (servicemodelsamples) was not an application. Right-click the folder, click "Properties" and click the "Create" button.
我也在尝试 Microsoft.ServiceModel.Samples.Calculator WCF 示例时遇到了这个问题。我正在使用 IIS 5.1。我通过确保自动生成的网站(servicemodelsamples)不是应用程序来解决它。右键单击该文件夹,单击“属性”,然后单击“创建”按钮。