启用asp.net兼容模式

时间:2016-02-29 13:58:36

标签: asp.net web-services rest compatibility

我正在尝试使用WCF 3.5构建一些简单的REST服务,并在IIS6上托管它们(是的,旧技术)。当我启用aspnet兼容性以访问http上下文时,浏览.svc文件会返回以下错误:

  

“无法激活该服务,因为它不支持ASP.NET   兼容性...添加AspNetCompatibilityRequirements属性   RequireMode设置为“允许”或的服务类型   '必需'。“

这就是我所做的,但我似乎无法让它发挥作用。

接口:

[ServiceContract]
public interface IService
{
    [OperationContract]
    [WebInvoke(
        Method = "GET",
        RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json,
        BodyStyle = WebMessageBodyStyle.WrappedRequest,
        UriTemplate = "foo"
    )]
    string foo();
}

实现:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed))] //or AspNetCompatibilityRequirementsMode.Required
public class Service : IService
{
    public string foo(){
        return "hello world!";
    }
}

的web.config:

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

我有什么遗失的吗?

0 个答案:

没有答案