1. 程式人生 > >WCF The service cannot be activated because it does not support ASP.NET compatibility

WCF The service cannot be activated because it does not support ASP.NET compatibility

測試釋出到虛擬目錄中時發生的報錯現象,由於不支援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 服務通過 實現來使用 HTTP 管道,其方式類似於處理 ASPX 頁和 ASMX Web 服務的請求。 因此,WCF 的行為在以下 ASP.NET 功能方面與 ASMX 相同:

  • 在 ASP.NET 相容模式中執行的 : WCF 服務可以訪問  以及與其關聯的狀態。

  • 基於檔案的授權:在 ASP.NET 相容模式中執行的 WCF 服務可以通過將檔案系統訪問控制列表 (ACL) 附加到服務的 .svc 檔案來獲得保護。

  • 可配置的 URL 授權:當 WCF 服務在 ASP.NET 相容模式中執行時,將對 WCF 請求強制執行 ASP.NET 的 URL 授權規則。

  • 擴充套件性:由於在 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 相容模式的應用程式內執行。  

[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 The service cannot be activated because it does not support ASP.NET compatibility

測試釋出到虛擬目錄中時發生的報錯現象,由於不支援asp.net相容性而導致服務無法啟用啟用。具體錯誤資訊如下:Server Error in '/Service2' Application. ------------------------------------------

[WARNING] The requested profile "pom.xml" could not be activated because it does not exist.解決方法

版權宣告:本文為博主原創文章,未經博主允許不得轉載。https://blog.csdn.net/zhangleiyes123/article/details/82665702 (1).之前專案打包都OK,不知道咋回事,突然出現如下圖的問題: (2).上網查找了好多,一直沒有解決,最後把

The requested profile "test" could not be activated because it does not exist.

SpringBoot專案在執行mvn install命令時出現以下問題: [WARNING] The requested profile "test" could not be activated

java.io.FileNotFoundException: class path resource ..cannot be opened because it does not exist

java ... mod ons exc pen 方法 except open java.io.FileNotFoundException: class path resource ..cannot be opened because it does not exist

解決CXF的java.io.FileNotFoundException: class path resource [META-INF/cxf/cxf-extension-soap.xml] cannot be opened because it does not exist

div light bst thread ast host ava ref off   以下是錯誤信息 九月 25, 2017 8:22:04 下午 org.springframework.web.context.support.XmlWebApplicationCont

SSM框架出現:class path resource [SpringMvc.xml] cannot be opened because it does not exist

def 文件 ati XML tco character java style cte 錯誤:class path resource [config/spring/springmvc.xml] cannot be opened because it does not exi

Maven 構建SSM架構是出現的異常:class path resource [mapper/*.xml] cannot be opened because it does not exist

異常資訊:  [INFO] Root WebApplicationContext: initialization started [WARNING] Exception encountered during context initialization - cancelling r

springboot activiti 報錯cannot be opened because it does not exist

Failed to process import candidates for configuration class [com.example.ActivitiApplication]; nested exception is java.io.FileNotFoundException: clas

報錯:java.io.FileNotFoundException: class path resource ..cannot be opened because it does not exist

配置spring是出現的問題: java.io.FileNotFoundException: class path resource ..cannot be opened because it does not exist    初學Spring在用Res

【錯誤解決】[Maven] cannot be opened because it does not exist錯誤[檔案無法編譯到target目錄下的解決方法]

使用IDEA搭建的Maven專案,在寫SpringEL和資源呼叫時出現瞭如下錯誤: 相信我,程式碼沒問題的、 Caused by: java.io.FileNotFoundException: class path resource [cn/hncu

class path resource [spring.xml] cannot be opened because it does not exist

    使用maven建立web工程,將spring配置檔案applicationContext.xml放在src/resource下,用Myeclipse編譯時提示class path resource [applicationContext.xml] cannot

class path resource [META-INF/xfire/services.xml] cannot be opened because it does not exist

如圖所示,錯誤就是找不到那個service.xml 但是仔細找找,那個檔案確確實實躺在那兒的。 那是什麼原因了,別人告訴我這個要看Class path。 System.getProperty("java.class.path") 用這個

IDEA Junit FileNotFoundException: class path resource [spring/spring.xml] cannot be opened because it does not exist

tst clas 指定 -- init project eclipse 分享 圖片 今天打算寫一個單元測試,但是已經有寫好的單元測試無論怎麽弄都提示文件不存在,自己一度以為是啟動方式不正確.這裏簡單記錄一下處理過程 1 異常信息: Caused by: org.sp

Dynamics CRM the field cannot be deleted because it is used in one or more process的解決方法

    在刪除一個查詢欄位時報如上的錯誤,報錯圖如下    第一想到的是這個欄位在哪個流程裡用了,去流程裡找遍了發現沒有哪個流程用到它,然後去開啟系統trace日誌,寄希望於有更詳細的日誌,結果又提示workflow,然後我們再去workflow

springMvc錯誤:class path resource [config/spring/springmvc.xml] cannot be opened because it does

錯誤:class path resource [config/spring/springmvc.xml] cannot be opened because it does not exist   錯誤原因:找不到我的springmvc.xml,在web.xml中是我引用路徑, 網上找到問題

intellij idea中出現class path resource [spring/applicationContext.xml] cannot be opened because it does

 Context initialization failed org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class

IOException parsing XML document from class path resource [xxx.xml] cannot be opened because it does

錯誤原因:使用註解的方式classpath沒有新增 例如: @ContextConfiguration(value = "classpath:applicationContext.xml")不要漏了classpath 引用spring核心配置檔案時,注意不要漏寫classpath ===

Springboot The requested profile "pom.xml" could not be activated because it doesn't not exists

後來 close vat 配置 cau activate pre 很多 pes 頭一次寫springboot項目,打成war包時,pom.xml也都配置了,網上查了很多資料說是maven環境和java環境的問題,但是看了後沒有發現什麽問題,刪了maven下的.m2maven

ueditor百度富文字編輯器linux下報錯: class path resource [config.json] cannot be resolved to absolute file path because it does not reside in the file system

具體報錯資訊如下 java.io.FileNotFoundException: class path resource [config.json] cannot be resolved to absolute file path because it does not reside in the fi

cannot be resolved to absolute file path because it does not reside in the file system

使用maven分模組元件專案的時候,domain中的實體的*.hbm.xml檔案不能被spring掃描到,因為聚合的時候核心包已經達成jar包了,所以要去jar中去找hbm.xml檔案 <!--注入sessionFactory -->     <bea