Faking HTTP PUT and DELETE

Topics: Web Api
Nov 1, 2010 at 4:31 PM

Hi,

Awesome work! In the past I've used the WCF REST starter kit to implement REST services and I've experienced its limitations.... WCF was built with SOAP and XML in mind and extending REST services based on that foundation (no pun intended) was rather painful (i.e. Working with the class Message). And now my question:

HTML 4 and XHTML 1.0 forms don't support the PUT and DELETE HTTP methods. Is there any plan to implement tunneling over POST (i.e. Rails) to get around this limitation?

Thanks!

Javier

Nov 1, 2010 at 10:04 PM

They are definitely considering it.  My response was they should implement it only if we can access the same extensibility mechanism :-).  It's not a straightforward as using a processor because the HTTP method is already been determined before the processor pipeline is hit.  To do it you need to hook into the the operation selection mechanism.   

Also, HTML5 Forms is no longer planning on doing PUT and DELETE.  It was removed recently.

 

 

Coordinator
Nov 2, 2010 at 3:12 AM

Our new Http Channels would be the place to do this.

Nov 4, 2010 at 2:42 PM

I've opened a case at http://wcfhttpcontrib.codeplex.com/workitem/1. Vote it up! I'm planning to work on this myself as soon as time permits.

Ryan

Nov 4, 2010 at 4:31 PM

Ryan,

I just voted this up.  I may try to work on this as well.  I used this one in the past for the REST Starter Kits Interceptors.

    public class XHttpMethodOverrideInterceptor : RequestInterceptor
    {
        public XHttpMethodOverrideInterceptor() : base(true) { }

        public override void ProcessRequest(ref RequestContext requestContext)
        {
            if (requestContext == null || requestContext.RequestMessage == null)
            {
                return;
            }
            Message message = requestContext.RequestMessage;
            HttpRequestMessageProperty reqProp = (HttpRequestMessageProperty)message.Properties[HttpRequestMessageProperty.Name];
            string methodOverrideVal = reqProp.Headers["X-HTTP-Method-Override"];
            if (!string.IsNullOrEmpty(methodOverrideVal))
            {
                reqProp.Method = methodOverrideVal;
            }
        }
    }
Coordinator
Nov 4, 2010 at 7:52 PM

The best place to handle this will be through the new channel model we are introducing. At that level you can easily change the headers and such before operation selection occurs.

Apr 17, 2011 at 8:11 AM

I've implemented this with the new message channels...

http://javiercrespoalvez.com/2011/04/tunnelling-put-and-delete-with-wcf-web.html

Coordinator
Apr 17, 2011 at 9:16 AM

Nice post Javi. I left a suggestion for you on your blog.

Aug 4, 2011 at 6:34 AM

Glenn,

Given that use of the X-HTTP-Method-Override header is a very common scenario, especially in the enterprise (where we are often only able to use GET, POST, HEAD, OPTIONS, and TRACE verbs) I would very much like to see support for override of original HTTP verb based on this header be supported out of the box in the WCF Web API.

I defintely think you should have a quick start that specifically covers how to use the X-HTTP-Method-Override header regardless of the direction the team decides to go.

Any time frame for when we we see a new drop with the channel model? Keep up the great work, I am looking forward to RTM.

Coordinator
Aug 4, 2011 at 7:12 AM

Channels are there now. If you look at javic's post you can see how to do it.

Aug 4, 2011 at 3:49 PM

Blocked by my work proxy, but I will definitely check out his blog post at home. I have been impressed by how extensible you have made this framework, seems like there is always a way to accomplish our goals.