我正在尝试使用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
Run Code Online (Sandbox Code Playgroud)
我完全没有任何线索,只是看起来它找不到我的组件.应该使用公共类正确编译代码.
这是我的.svc文件:
<%@ ServiceHost Language="C#" Debug="true" Service="QS.DialogManager.Communication.IISHost.RecipientService" CodeBehind="RecipientService.svc.cs" %>
Run Code Online (Sandbox Code Playgroud)
我试图创建一个非常非常简单的服务,其中包含的内容只是看看是否可行,但仍会显示相同的旧错误.
The type 'IISHost.Service1', provided as the Service attribute value in the ServiceHost directive could not be found.
Run Code Online (Sandbox Code Playgroud)
Pet*_*nar 72
问题也可能是svc文件中的不同命名空间,因为它位于svc.cs文件中.
在svc文件中,命名空间必须采用以下格式.
Service="Namespace.SvcClassName"
Run Code Online (Sandbox Code Playgroud)
Kon*_*kus 66
方案一:
此消息通常是由于IIS 7配置问题.如果您习惯于创建指向服务所在文件夹的虚拟目录,则该目录不再有效.现在,您需要使用"创建应用程序..."选项.
其他选择:
bai*_*yrt 31
我知道这可能是"明显的"答案,但它让我感到沮丧.确保bin文件夹中的项目有一个dll.当该服务发布时,发布它的人删除了dll,因为他认为他们在GAC中.专门用于项目的那个(QS.DialogManager.Communication.IISHost.RecipientService.dll,在这种情况下)不在那里.
出于非常不同的原因,出现相同的错误.
小智 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"%>
Run Code Online (Sandbox Code Playgroud)
此示例适用于使用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>
Run Code Online (Sandbox Code Playgroud)
小智 9
仔细检查您是否从.svc文件中的ServiceHost指令引用了正确的类型.这是如何做...
我有相同的异常,这是由于.svc文件中没有正确提到的类型
我纠正了下面的修复.
如果你的.svc.cs有这样的类
namespace Azh.Services.MyApp
{
public class WcfApp : FI.IWcfAppService
{
...
}
}
Run Code Online (Sandbox Code Playgroud)
为此,.svc文件应如下所示
<%@ ServiceHost Language="C#" Debug="true" Service="Azh.Services.MyApp.WcfApp" CodeBehind="WcfApp.svc.cs" %>
Run Code Online (Sandbox Code Playgroud)