3

Some background

I am planning to writing a REST service which helps facilitate collaboration between multiple client systems. Similar to how git or hg handle things I want the client to perform all merging locally and for the server to reject new changes unless they have been merged with existing changes.

How I want to handle it

I don't want clients to have to upload all of their change sets before being told they need to merge first. I would like to do this by performing a POST with the Expect 100 Continue header. The server can then verify that it can accept the change sets based on the header information (not hard for me in this case) and either reject the request or send the 100 Continue status through to the client who will then upload the changes.

My problem

As far as I have been able to figure out so far ASP.NET doesn't support this scenario, by the time you see the request in your controller actions the POST body has normally already been completely uploaded. I've had a brief look at WCF REST but I haven't been able to see a way to do it there either, their conditional PUT example has the full request body before rejecting the request.

I'm happy to use any alternative framework that runs on .net or can easily be made to run on Windows Azure.

Caleb Vear
  • 2,637
  • 2
  • 21
  • 20
  • 1
    I believe that IIS automatically responds "continue" to Expect 100-Continue header. You probably need to look at customizing IIS pipeline - it may be possible using HTTP Module in IIS7. See related question: http://stackoverflow.com/questions/1778160/asp-net-overriding-iis-response-to-expect-100-header – VinayC Feb 06 '12 at 07:25
  • It is incredibly annoying that IIS does this, it limits you from making full use of the HTTP protocol. Is there another .net web server I can run instead which will let me handle this? If not I will probably just do it another way, by making two requests the first one determines whether the second should succeed or not. – Caleb Vear Feb 06 '12 at 19:36
  • There are some commercial products but I am unaware of their pro/cons - see http://www.neokernel.com/content.agent?page_name=Home and http://ultidev.com/products/UWS-Cassini-Pro/Default.aspx. There is a open source project to further the development of Cassini Web Server (one that comes with VS): http://cassinidev.codeplex.com/. Finally there is a mono module that will allow you to run ASP.NET on servers like Apache but I am doubtful if mono has support for .NET 4 - see http://www.mono-project.com/ASP.NET#Running_ASP.NET_applications – VinayC Feb 07 '12 at 04:56

1 Answers1

0

I can't recommend WcfRestContrib enough. It's free, and it has a lot of abilities.

But I think you need to use OpenRasta instead of WCF in order to do what you're wanting. There's a lot of stuff out there on it, like wiki, blog post 1, blog post 2. It might be a lot to take in, but it's a .NET framework thats truly focused on being RESTful, and not RPC like WCF. And it has the ability work with headers, like you asked about. It even has PipelineContributors, which have access to the whole context of a call and can halt execution, handle redirections, or even render something different than what was expected.

EDIT: As far as I can tell, this isn't possible in OpenRasta after all, because "100 continue is usually handled by the hosting environment, not by OR, so there’s no support for it as such, because we don’t get a chance to respond in the asp.net pipeline"

Precious Roy
  • 1,086
  • 1
  • 9
  • 19
  • Thanks for the link to OpenRasta, it looks good and I might end up using it. So far I haven't been able to see how you can control when 100 Continue is sent though even with a PipelineContributor. – Caleb Vear Feb 20 '12 at 10:02
  • Sorry for misleading you, I guess we both learned something. Now I'm really curious how this would be accomplished in a .NET environment. – Precious Roy Feb 20 '12 at 15:00
  • It would seem to do this in .NET you need to create your own web server and just listen to port 80. I can understand why it is this way as it would make it much harder to bind model for you action as the action would have to be called before the message body was posted. – Caleb Vear Mar 04 '12 at 03:00
  • I was just looking at my profile and saw this unanswered question. I've decided I should mark your answer as correct because in the edit you correctly state that it isn't possible in the asp.net pipeline. – Caleb Vear Dec 10 '13 at 22:13