2012-09-25 19 views
1

我在VS 2010中使用WCF REST template爲我的應用程序構建RESTful Web服務。我已經完成了所有GET,但現在正在嘗試處理更新,並且即使它顯示在幫助文件中,我仍然在PUT上獲得404。HTTP 404與REST服務中的PUT請求

截斷web.config

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
    <add name="UrlRoutingModule" 
     type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> 
    </modules> 
    <validation validateIntegratedModeConfiguration="true" /> 
    <handlers> 
    <add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd" /> 
    </handlers> 
</system.webServer> 
<system.serviceModel> 
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" /> 
    <standardEndpoints> 
    <webHttpEndpoint> 
     <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true" /> 
    </webHttpEndpoint> 
    </standardEndpoints> 
</system.serviceModel> 

正如你所看到的,所有的動詞爲UrlRoutingHandler啓用。我錯過了什麼?

(請注意,我用的IIS 7,但我不得不運行經典模式的應用程序池以模擬釋放服務器的行爲,這是對IIS 6)

回答

1

多後對以下兩個配置更改的組合進行故障排除似乎已經修復了它。

  1. 卸下的WebDAV處理程序
  2. 添加PUT和DELETE動詞爲ExtensionlessUrlHandler

(這是一個佔位符,以使下面降價代碼視圖)

<handlers> 
    <remove name="WebDAV" /> 
    <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" /> 
    <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" /> 
    <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" 
     modules="IsapiModule" scriptProcessor="c:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" 
     resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness32" 
     responseBufferLimit="0" /> 
    <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE" 
     modules="IsapiModule" scriptProcessor="c:\Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" 
     resourceType="Unspecified" requireAccess="Script" preCondition="classicMode,runtimeVersionv4.0,bitness64" 
     responseBufferLimit="0" /> 
</handlers>