WCF 無法啟用服務,因為它不支援 ASP.NET 相容性。已為此應用程式啟用了 ASP.NET 相容性

衣舞晨風發表於2015-08-19

作者:jiankunking 出處:http://blog.csdn.net/jiankunking

錯誤資訊:

無法啟用服務,因為它不支援 ASP.NET 相容性。已為此應用程式啟用了 ASP.NET 相容性。請在 web.config 中關閉 ASP.NET 相容性模式,或將 AspNetCompatibilityRequirements 特性新增到服務型別且同時將 RequirementsMode 設定為“Allowed”或“Required”。 
說明: 執行當前 Web 請求期間,出現未經處理的異常。請檢查堆疊跟蹤資訊,以瞭解有關該錯誤以及程式碼中導致錯誤的出處的詳細資訊。 

異常詳細資訊: System.InvalidOperationException: 無法啟用服務,因為它不支援 ASP.NET 相容性。已為此應用程式啟用了 ASP.NET 相容性。請在 web.config 中關閉 ASP.NET 相容性模式,或將 AspNetCompatibilityRequirements 特性新增到服務型別且同時將 RequirementsMode 設定為“Allowed”或“Required”。

源錯誤: 

執行當前 Web 請求期間生成了未經處理的異常。可以使用下面的異常堆疊跟蹤資訊確定有關異常原因和發生位置的資訊。  

堆疊跟蹤: 


[InvalidOperationException: 無法啟用服務,因為它不支援 ASP.NET 相容性。已為此應用程式啟用了 ASP.NET 相容性。請在 web.config 中關閉 ASP.NET 相容性模式,或將 AspNetCompatibilityRequirements 特性新增到服務型別且同時將 RequirementsMode 設定為“Allowed”或“Required”。]
   System.ServiceModel.Activation.HostedAspNetEnvironment.ValidateCompatibilityRequirements(AspNetCompatibilityRequirementsMode compatibilityMode) +184808
   System.ServiceModel.Description.DispatcherBuilder.ValidateDescription(ServiceDescription description, ServiceHostBase serviceHost) +391
   System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost) +306
   System.ServiceModel.ServiceHostBase.InitializeRuntime() +82
   System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout) +64
   System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout) +789
   System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath) +287
   System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath) +1132

[ServiceActivationException: 由於編譯過程中出現異常,無法啟用服務“/AMACTEST/RightManagementServer.svc”。異常訊息為: 無法啟用服務,因為它不支援 ASP.NET 相容性。已為此應用程式啟用了 ASP.NET 相容性。請在 web.config 中關閉 ASP.NET 相容性模式,或將 AspNetCompatibilityRequirements 特性新增到服務型別且同時將 RequirementsMode 設定為“Allowed”或“Required”。。]
   System.Runtime.AsyncResult.End(IAsyncResult result) +890624
   System.ServiceModel.Activation.HostedHttpRequestAsyncResult.End(IAsyncResult result) +180062
   System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +136

解決方案:

1、修改相應服務.svc.cs,在類上新增以下標識

using System.ServiceModel.Activation ;
[AspNetCompatibilityRequirements (RequirementsMode=AspNetCompatibilityRequirementsMode.Required)]


據說:啟用了AJAX的WCF服務是預設新增的


請移步到小注中的連結,謝謝


小注:

更詳細的問題分析參考:

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





相關文章