为什么 HTTP DELETE 谓词返回 405 错误 - 在 IIS 7.5 上运行的 RESTful WCF 服务不允许使用该方法?

发布于 2024-10-07 05:52:40 字数 508 浏览 0 评论 0原文

任何人都可以阐明这一点吗?我觉得我今天浪费了一整天的时间在互联网上寻找和搜索有关如何执行此操作的任何信息。我创建了一个非常简单的 WCF RESTful 服务。它基本上是一个概念证明。我背后有一个简单的数据库,我只是想让它工作,以便我可以查看、创建、更新和删除项目。现在我只能查看和更新​​工作。我稍后会解决创建问题。目前我无法弄清楚为什么删除不起作用。到目前为止我发现的几乎所有内容都告诉我需要禁用 WebDAV 模块。我这样做了,然后我就开始工作了。但我无法让 DELETE 工作。每当我尝试通过服务调用 DELETE 时,都会收到以下错误:

远程服务器返回意外响应:(405) 不允许方法。

所以我的服务器上的某个地方似乎不允许使用 DELETE 动词。但对于我的一生,我无法弄清楚。我已经检查了处理程序映射,并且处理程序允许 .SVC 扩展名的所有动词。我已禁用 WebDAV。我不太确定还能去哪里寻找。我在 Windows Server 2008 R2 上使用 IIS 7.5。

(如果有帮助的话我可以提供代码)

谢谢, 科里

Can anyone shed any light on this? I feel like I have wasted the entire day today hunting and searching the internet for any scrap of information about how to do this. I have created a very simple WCF RESTful service. It is basically a proof of concept. I have a simple database behind it and I am just trying to get it working so that I can view, create, update and delete items. Right now I only have view and update working. I'll tackle create later. For now I can't figure out why the delete doesn't work. Almost everything I have found so far tells me that I need to disable the WebDAV module. I did that and then I got PUT to work. But I can not get DELETE to work. Whenever I attempt to call DELETE through my service I get the following error:

The remote server returned an unexpected response: (405) Method Not Allowed.

So it seems like somewhere on my server it is not allowing the DELETE verb. But for the life of me I can not figure it out. I already checked the Handler Mappings and the handler allows all verbs for the .SVC extension. I have disabled WebDAV. I'm not really sure where else to look. I am using IIS 7.5 on Windows Server 2008 R2.

(I can provide code if it would help at all)

Thanks,
Corey

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

北方的巷 2024-10-14 05:52:40

万一有人遇到同样的问题。

您可以尝试以下另一种方法。

在 web.config 中

<system.webServer>
    <modules>
      <remove name="WebDAVModule" />
    </modules>
    <handlers>
      <remove name="WebDAV" /> 
    </handlers>
</system.webServer>

In case anyone having the same issue.

Here is another way you can try.

in web.config

<system.webServer>
    <modules>
      <remove name="WebDAVModule" />
    </modules>
    <handlers>
      <remove name="WebDAV" /> 
    </handlers>
</system.webServer>
假情假意假温柔 2024-10-14 05:52:40

我只是花了很多时间试图弄清楚为什么在使用 DELETE 动词时我总是收到 405 Method Not Allowed 错误。我读到的所有内容都说要从 IIS 中卸载 WebDAV,但这似乎会破坏 IIS,因为所有站点都会出现 503 错误。我重新安装了它,然后在 IIS 中查找一些设置。

事实证明,WebDAV 是问题所在,并且它在 IIS 功能页面上有一个名为“WebDAV Authoring”的节点。单击该按钮后,您可以单击WebDAV 设置... 以获取属性页面。在“请求过滤行为”部分中,将允许动词过滤设置为False似乎对我有用(YMMV)。

在谷歌搜索解决方案时,这似乎是一个受欢迎的结果,所以我想我应该将其添加到建议的解决方案列表中。

I just spent a ton of time trying to figure out why I kept getting 405 Method Not Allowed when using the DELETE verb. Everything I read said to uninstall WebDAV from IIS, but that seemed to break IIS in that all sites gave 503 errors. I reinstalled it, then went about looking in IIS for some setting.

It turns out that WebDAV is the problem, and it has a node on the IIS features page named "WebDAV Authoring". Clicking on that lets you then click on WebDAV Settings... to get the properties page. In the section Request Filtering Behavior, set Allow Verb Filtering to False seemed to do the trick for me (YMMV).

This seemed to be a popular result when googling for a solution, so I thought I'd add to the list of suggested solutions.

北音执念 2024-10-14 05:52:40

在 IIS 管理器中打开网站的处理程序

映射编辑要用于 DELETE 的每个处理程序,单击“请求限制”,选择“动词”选项卡,然后将 DELETE 添加到“以下之一”列表,或者如果适合您的关注点,则允许所有动词。

您可能需要重新启动网站和/或重新编译代码

Open your website's Handler Mappings in IIS Manager

Edit each handler you want to DELETE with, clicking Request Restrictions, choosing the Verbs tab, then add DELETE to the "One of the following" list or, if appropriate within your concerns, allow all verbs.

You might need to restart your website and/or recompile your code

水水月牙 2024-10-14 05:52:40

好吧,我不确定这是否真的是我问题的答案,但它确实解决了问题。我只是在 Visual Studio 中启动了一个新项目,这次我使用了我在网上找到的 .NET REST 服务模板。然后我转移了之前尝试中的旧代码并在新项目中使用了它。它就像一个魅力。所有四个动词现在都可以正常工作(GET、PUT、POST 和 DELETE)。所以它现在正在发挥作用。

科里

Well I'm not sure if this is really an answer to my question but it did solve the problem. I simply started a new project in Visual Studio and this time I used the .NET REST Service template that I found online. Then I transferred the old code I had from my previous attempt and used it in the new project. It worked like a charm. All four verbs work correctly now (GET, PUT, POST and DELETE). So it is working now.

Corey

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文