WCF The service cannot be activated because it does not supp

测试发布到虚拟目录中时发生的报错现象,由于不支持asp.net兼容性而导致服务无法激活启用。

具体错误信息如下:

Server Error in ‘/Service2’ Application.——————————————————————————–The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the service type with RequirementsMode setting as ‘Allowed’ or ‘Required’. 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 service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the service type with RequirementsMode setting as ‘Allowed’ or ‘Required’.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 service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the service type with RequirementsMode setting as ‘Allowed’ or ‘Required’.] System.ServiceModel.Activation.HostedAspNetEnvironment.ValidateCompatibilityRequirements(AspNetCompatibilityRequirementsMode compatibilityMode) +120262 System.ServiceModel.Activation.AspNetCompatibilityRequirementsAttribute.System.ServiceModel.Description.IServiceBehavior.Validate(ServiceDescription description, ServiceHostBase serviceHostBase) +31 System.ServiceModel.Description.DispatcherBuilder.ValidateDescription(ServiceDescription description, ServiceHostBase serviceHost) +190 System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +109 System.ServiceModel.ServiceHostBase.InitializeRuntime() +60 System.ServiceModel.ServiceHostBase.OnBeginOpen() +27 System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +50 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +318 System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +206 System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +651[ServiceActivationException: The service ‘/Service2/DataService.svc’ cannot be activated due to an exception during compilation. The exception message is: The service cannot be activated because it does not support ASP.NET compatibility. ASP.NET compatibility is enabled for this application. Turn off ASP.NET compatibility mode in the web.config or add the AspNetCompatibilityRequirements attribute to the service type with RequirementsMode setting as ‘Allowed’ or ‘Required’..] System.Runtime.AsyncResult.End(IAsyncResult result) +687598 System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +190 System.ServiceModel.Activation.ServiceHttpHandler.EndProcessRequest(IAsyncResult result) +6 System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +96——————————————————————————–Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

可通过下面的配置(位于应用程序的 Web.config 文件中)在应用程序级别上启用 WCF 的 ASP.NET 兼容模式:

<system.serviceModel><serviceHostingEnvironment aspNetCompatibilityEnabled="true" /> </system.serviceModel>

如果没有指定,则此值默认为“true”。若将此值设置为“false”,则指示在应用程序中运行的所有 WCF 服务将不在 ASP.NET 兼容模式中运行。

由于 ASP.NET 兼容模式暗含的请求处理语义与 WCF 默认值完全不同,因此单独的服务实现能够控制其是否在已启用 ASP.NET 兼容模式的应用程序内运行。服务可以使用AspNetCompatibilityRequirementsAttribute来指示其是否支持 ASP.NET 兼容模式。此特性的默认值为Allowed。

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

public class CalculatorService : ICalculatorSession

{//Implement calculator service methods.}

拿望远镜看别人,拿放大镜看自己。

WCF The service cannot be activated because it does not supp

相关文章:

你感兴趣的文章:

标签云: