2010-06-18 36 views
0

我試圖測試與我的WebCache REST服務屬性WCF REST - 如何測試的WebCache

[ServiceContract] 
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 
public partial class MyContract : IMyContract 
    { 
     [OperationContract()] 
     [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "items/{code}" 
     [WebCache(CacheProfileName = "NoCacheProfile")] 
     public ItemDTO GetItem(string code) 

當我嘗試打開主機

WebServiceHost host = new WebServiceHost2(typeof(MyContract), true, new Uri("http://localhost:7777/MySvc")); 
host.Open(); 

我得到下面的異常

[System.NotSupportedException] = {「WebCacheAttribute僅在AspNetCompatibility模式下受支持。」}

回答

0

如果WebCacheAttribute僅在AspNetCompatibility模式支持,您可能需要在Web.config中聲明AspNetCompatibilityRequirementsMode =在「AspNetCompatibilityRequirements」屬性必需和檢查服務配置,以確保它已啓用:

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

欲瞭解更多信息,請請訪問: http://msdn.microsoft.com/en-us/library/aa702682.aspx