Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF REST service hosted in IIS does not support PUT and DELETE

I created a WCF REST (aka WebHttp) service in .NET 4, using Microsoft's WCF REST Service Template 40. I am hosting the service in IIS 6.

The Service Template uses the RouteTable in the Global.asax as a way to create "clean" URL's that don't include ".svc" in them. For example:

http:// localhost / flights / 878

GET and POST work fine against this URL, but PUT and DELETE result in HTTP 501, "Not implemented".

If I create a simple .svc file like this:

<%@ ServiceHost Language="C#" Debug="true" Service="MyProject.FlightsService"%>

then I can use PUT and DELETE against this URL:

http:// localhost / flightsservice.svc / 878

Does anyone know if it's possible to get PUT and DELETE to work against the "clean" URL above? It seems that there is no way to configure IIS to allow this because there is no file extension to configure settings for, and I don't want to allow PUT and DELETE globally.

like image 313
Mike Taverne Avatar asked Aug 21 '10 01:08

Mike Taverne


2 Answers

I haven't worked with IIS6 in a while (and I don't have it installed, so I'm going off memory here), but I had to implement something similar with IIS6 for routing extensionless URLs in IIS6.

You can enable wildcard script mappings on a folder by folder basis by hacking IIS Manager. This blog post is what I followed and it works really well (and this link provides a little more background). It's really a bug in the Manager, not IIS itself (at least that's what I tell myself).

Can you reference your services in a sub-folder in your site (e.g. http://localhost/services/flight/878)? If so, and if you implement the IIS Manager hack above, I think you can enable all HTTP verbs for that directory. Again, I'm going off memory (and we only implemented GETs and POSTs, so I didn't deal with PUTs and DELETEs), so I hope I'm getting this right.

Let me know if you need more info or if my memory is slipping. :) I hope this helps!

like image 115
David Hoerster Avatar answered Oct 18 '22 04:10

David Hoerster


If your web application is getting deployed to multiple dev/production environments, then the best way seems to be disable WebDAV at the web.config level. To do this, remove the WebDAVModule and the WebDAV handler as in the below example:

<system.webserver>
  <modules>
    <remove name="WebDAVModule" />
  </modules>
  <handlers>
    <remove name="WebDAV" />
  </handlers>
</system.webserver>
like image 2
DanilF Avatar answered Oct 18 '22 03:10

DanilF