WCF REST - 如何测试WebCache

时间:2010-06-18 17:34:59

标签: wcf unit-testing rest

我正在尝试使用WebCache属性

测试我的REST服务
[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] = {“仅在AspNetCompatibility模式下支持WebCacheAttribute。”}

1 个答案:

答案 0 :(得分:0)

如果仅在AspNetCompatibility模式下支持WebCacheAttribute,则可能需要在“AspNetCompatibilityRequirements”属性中声明AspNetCompatibilityRequirementsMode = Required并检查Web.config中的服务配置以确保它已启用:

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

欲了解更多信息,请访问: http://msdn.microsoft.com/en-us/library/aa702682.aspx