zoukankan      html  css  js  c++  java
  • WCF 4.0 REST服务解决Method Not Allowed错误


    问题:
     使用WCF 4.0 开发REST服务,部署到windows 7 64位 IIS 7.5 (应用程序池选择的是ASP.NET V4.0) 上GET,POST方式都能成功;但是PUT,DELETE报错:
    HTTP 错误 405.0 - Method Not Allowed
    无法显示您正在查找的页面,因为使用了无效方法(HTTP 谓词)。

    但是如果使用VS2010 调试模式,GET,POST,PUT,DELETE都成功,这说明代码本身没有任何问题,
    问题出在IIS 7.5 设置上。

    在显示的错误页面上:可以看到如下信息,知道处理模块为WebDAVModule
    模块
    WebDAVModule
    通知
    MapRequestHandler
    处理程序
    StaticFile
    错误代码
    0x00000000
    然后查看Headers  发现允许的谓词如下: Allow: GET, HEAD, OPTIONS, TRACE

    解决办法:
    设置IIS 7.5 -》 处理程序映射
    WebDAV-》请求限制-》谓词 勾选“全部谓词”

    后来我由搜到一篇博客,你也可以尝试如下方法解决,我没有测试过是否可行:
    These days I run into this issue: my restful service hosting with IIS 7.5 and using Asp.net 4.0 not support PUT or DELETE verbs for http request.
    solved.
    the following configuration setting fixed our problem:
         <modules runAllManagedModulesForAllRequests="true">
            <remove name="WebDAVModule" />
         </modules>
    As reported in [1], this is due to the WebDAV module now being an integral part of IIS 7.5 (and on 7.0 if installed). Removing the module allowed all 4 verbs to come through to our service tier. Cheers!
    [1]:  http://shouldersofgiants.co.uk/Blog/post/2009/11/27/HTTP-Error-405-With-ASPNet-MVC-and-HTTP-PUT-on-IIS-75.aspx

    源文档 <http://www.cnblogs.com/cosophy/archive/2011/03/18/1988352.html>

  • 相关阅读:
    Django models中的null和blank的区别
    微服务
    幂等性
    restful规范
    related_name
    数据库 引擎,数据类型,约束
    数据库 基本操作
    python 常见算法
    python if,循环的练习
    python数据类型、if判断语句
  • 原文地址:https://www.cnblogs.com/dbasys/p/2239076.html
Copyright © 2011-2022 走看看