8

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Mike Taverne
  • 83
  • 1
  • 3
  • See how a similar problem was solved on IIS 7.5 [here](http://stackoverflow.com/questions/3745015/webdav-troubles-for-restfull-wcf-web-service). The solution is elegant. – lmsasu Sep 19 '10 at 13:28

2 Answers2

4

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!

David Hoerster
  • 28,421
  • 8
  • 67
  • 102
  • Thanks, this worked! Since my IIS application will contain only services, I set the wildcard mapping for the entire application as described in the second link you posted. Thanks very much! Mike – Mike Taverne Aug 23 '10 at 17:41
  • Gotta love those "undocumented" features. :) Glad it worked for you. – David Hoerster Aug 23 '10 at 17:44
2

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>
Bo Persson
  • 90,663
  • 31
  • 146
  • 203
DanilF
  • 533
  • 2
  • 11
  • 1
    the question was how to enable PUT and DELETE in IIS on an application level. – deleted_user Sep 23 '12 at 08:27
  • 1
    Yes, this will cause IIS to allow it for just the current application, without enabling it globally, as the original poster asked. If you do not remove the WebDAV module and handler, PUT and DELETE requests will get hijacked by them and will not work. – DanilF Oct 07 '12 at 19:01