WCF The service cannot be activated because it does not support ASP.NET compatibility
作者:jiankunking 出處:http://blog.csdn.net/jiankunking
測試釋出到虛擬目錄中時發生的報錯現象,由於不支援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
中文版錯誤資訊:點選開啟連結
解決方案:
1、web.config中增加
<serviceHostingEnvironment aspNetCompatibilityEnabled="false">
注意這個是放在<system.serviceModel>中的。2、在wcf的服務類加上附加屬性 AspNetCompatibilityRequirements
其實,通過閱讀小注可以發現,下面兩種方式均可:
小注:
1、ServiceHostingEnvironment.AspNetCompatibilityEnabled 屬性:
獲取一個值,該值指示此服務是否在 ASP.NET HTTP 應用程式管道的上下文中執行。
如果為當前 AppDomain 啟用了 ASP.NET 相容性,則為 true;否則為 false。 預設值為 false。
2、AspNetCompatibilityRequirementsMode 列舉:
指定 Windows Communication Foundation (WCF) 服務是否(或能否)以與 ASP.NET 相容的模式執行。
3、在 ASP.NET 相容模式中承載 WCF 服務
儘管 WCF 模型旨在跨宿主環境和傳輸保持行為的一致性,但經常在一些方案中,應用程式中不要求這種程度的靈活性。 WCF 的 ASP.NET 相容模式適用於具有以下特點的方案:不需要具有在 IIS 外部承載或通過 HTTP 之外的協議進行通訊的能力,但使用 ASP.NET Web 應用程式平臺的所有功能。
在預設的並行配置中,承載基礎結構的 WCF 截獲 WCF 訊息並將其路由到 HTTP 管道之外;與此不同的是,在 ASP.NET 相容模式中執行的 WCF 服務完全參與 ASP.NET HTTP 請求生命週期。 在相容模式中,WCF 服務通過IHttpHandler 實現來使用 HTTP 管道,其方式類似於處理 ASPX 頁和 ASMX Web 服務的請求。 因此,WCF 的行為在以下 ASP.NET 功能方面與 ASMX 相同:
在 ASP.NET 相容模式中執行的 HttpContext: WCF 服務可以訪問 Current 以及與其關聯的狀態。
基於檔案的授權:在 ASP.NET 相容模式中執行的 WCF 服務可以通過將檔案系統訪問控制列表 (ACL) 附加到服務的 .svc 檔案來獲得保護。
可配置的 URL 授權:當 WCF 服務在 ASP.NET 相容模式中執行時,將對 WCF 請求強制執行 ASP.NET 的 URL 授權規則。
HttpModuleCollection 擴充套件性:由於在 ASP.NET 相容模式中執行的 WCF 服務完全參與 ASP.NET HTTP 請求生命週期,因此在 HTTP 管道中配置的任何 HTTP 模組能夠在服務呼叫前後的 WCF 請求上進行操作。
ASP.NET 模擬:WCF 服務使用 ASP.NET 模擬執行緒的當前標識來執行,如果已為應用程式啟用 ASP.NET 模擬,則該標識可能與 IIS 程式標識不同。 如果為某個特定服務操作同時啟用 ASP.NET 模擬和 WCF 模擬,則服務模擬最終使用從 WCF 獲得的標識來執行。
可通過下面的配置(位於應用程式的 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.}
下表演示應用程式範圍的相容模式設定如何與單獨服務指定的支援級別互動:
應用程式範圍的相容模式設定 | [AspNetCompatibilityRequirementsMode] 設定 | 觀察到的結果 |
---|---|---|
aspNetCompatibilityEnabled = “true” | 服務成功啟用。 | |
aspNetCompatibilityEnabled = “true” | 服務成功啟用。 | |
aspNetCompatibilityEnabled = “true” | 服務接收訊息時發生啟用錯誤。 | |
aspNetCompatibilityEnabled = “false” | 服務接收訊息時發生啟用錯誤。 | |
aspNetCompatibilityEnabled = “false” | 服務成功啟用。 | |
aspNetCompatibilityEnabled = “false” | 服務成功啟用。 |
說明 |
---|
IIS 7.0 和 WAS 允許 WCF 服務通過 HTTP 之外的協議進行通訊。 但是,在已啟用 ASP.NET 相容模式的應用程式中執行的 WCF 服務不允許公開非 HTTP 終結點。 在服務接收其第一條訊息時,這種配置會生成啟用異常。 |
有關為 WCF 服務啟用 ASP.NET 相容模式的更多資訊,請參見 AspNetCompatibilityRequirementsMode 和ASP.NET 相容性示例。
相關文章
- does not support SSL connections
- wlan0 interface does‘t support scanning
- JDK 載入jar中的檔案資源出現Cannot be resolved to absolute file path because it does not reside in the file systemJDKJARIDE
- Error: --recode does not support multipass recoding of very large files.Error
- grep: PCRE does not support L, l, N{name}, U, or u
- WCF與ASP.NET Core效能比較ASP.NET
- Client does not support authentication protocol requested by server; consider upgrading MySQL clientclientProtocolServerIDEMySql
- Error:Cannot build artifact xxx:war exploded‘ because it is included into a circular dependencyErrorUI
- onnx模型轉openvino報錯nGraph does not support the following ONNX operations: If模型
- Cannot load from short array because "sun.awt.FontConfiguration.head" is nullNull
- Job for docker.service failed because the control process exited with error codeDockerAIError
- sqlserver bulk insert報錯Cannot bulk load because the file could not be opened.SQLServer
- [20200416]ORA-01187 cannot read from file because it failed verification tests.AI
- 【Azure Cloud Service】使用RESTAPI更新Cloud Service(Extended Support) 中所配置的證書CloudRESTAPI
- [fabric]Cannot start service orderer: Mounts denied: In MacMac
- 高版本mysql訪問出現Client does not support authentication protocol requested by server;MySqlclientProtocolServer
- Job for mysqld.service failed because the control process exited with error code...MySqlAIError
- 【Azure Cloud Service】使用RESTAPI更新Cloud Service(Extended Support) 中所配置的證書HqCloudRESTAPI
- Load balancer does not contain an instance for the service service-B [503] during [POST] 問題解決AI
- Dynamics CRM the field cannot be deleted because it is used in one or more process的解決方法delete
- iis 0x80070032 Cannot read configuration file because it exceeds the maximum file size
- 舊 WCF 專案成功遷移到 asp.net core web apiASP.NETWebAPI
- Dynamics CRM Plug-in assembly does not contain the required types or assembly content cannot be...AIUI
- 【Azure Cloud Service】使用Key Vault Secret新增.CER證書到Cloud Service Extended Support中Cloud
- ORA-12514:TNS:listener does not currently know of service requested in connect descriptor
- CMake Error: add_executable cannot create target ““ because another target with the same name已解決Error
- [20181011]ORA-44777 – Pluggable database service cannot be started.txtDatabase
- Job for mysqld.service failed because the control process exited with error code錯誤解決MySqlAIError
- 安裝MySQL出現Job for mysqld.service failed because the control process exited with error codeMySqlAIError
- Centos httpd模組 Job for httpd.service failed because the control process exited with error code.CentOShttpdAIError
- 關於Cannot resolve scoped service from root provider解決方案IDE
- Mysql啟動報錯:Job for mysqld.service failed because the control process exited with error code.MySqlAIError
- Docker安裝MySQL8.0.39報錯:Fatal glibc error: CPU does not support x86-64-v2DockerMySqlError
- navicat本地連線mysql出現1251--Client does not support authentication protocol requested by server的解決方法MySqlclientProtocolServer
- 在docker中啟動服務報錯:New main PID 558 does not belong to serviceDockerAI
- WCF系列教程地址
- Navicat 遠端連線docker容器中的mysql 報錯1251 - Client does not support authentication protocol 解決辦法DockerMySqlclientProtocol
- Announcing MSTest Framework support for .NET Core RC2 / ASP.NET Core RC2[譯]FrameworkASP.NET
- WCF雙工通訊