If anyone has any insight into these PUT/POST issues that many are having, I would most appreciate it. I've explored every possible solution and come up empty.
A couple previous posts that illustrate the problem:
http://forums.asp.net/t/1788731.aspx/1?PUT+handler+parameter+not+getting+set+from+URI
http://forums.asp.net/t/1776856.aspx/1?RE+Are+there+any+known+issues+with+PUT+and+DELETE+
"System.Web.Http.HttpResponseException occurred Message=The parameters dictionary contains a null entry for parameter 'communityId' of non-nullable type 'System.Int32' for method"
The communityMembership DTO gets deserialized and set properly, but neither URI parameter works. Please confirm this is a major bug.
Other Web API Notes:
ObjectContent constructors should be made public.
IActionHttpMethodSelector should be made public. Why is this internal? What if I want to create an [HttpPatch] attribute?
MVC error handling should not interfere with Web API. 404 Errors: MVC by default will replace your own response message (even if content has already been set) with a default 404 error page. Temporary Solution:
RegisterServiceRoute is part of my application web api bootstrapper. (NContext) Essentially it just registers a route that will later be added
to the routing table.
BTW: It is not just about clearing the formatters collection but about removing the standard json formatter. It seems that the standard json formatter just need to be included in the formatters collections.
Wow, thanks! Not clearing the formatters fixed this for me too.
Been scratching my head for ages especially as it was working before but at some point I'd read about clearing the formatters and hadn't spotted it had broken this (note to self - improve the test suite to pick this up!).
dgdev
Member
22 Points
18 Posts
Put is definitely broken
Apr 05, 2012 03:01 PM|LINK
If anyone has any insight into these PUT/POST issues that many are having, I would most appreciate it. I've explored every possible solution and come up empty.
A couple previous posts that illustrate the problem:
http://forums.asp.net/t/1788731.aspx/1?PUT+handler+parameter+not+getting+set+from+URI
http://forums.asp.net/t/1776856.aspx/1?RE+Are+there+any+known+issues+with+PUT+and+DELETE+
Route:
routingManager.RegisterServiceRoute( routeName: "Community Membership1", routeTemplate: "communities/{communityId}/membership/{userId}", defaults: new { controller = "Membership" }, constraints: new { communityId = @"\d+", userId = @"\d+" });Action:
Result:
"System.Web.Http.HttpResponseException occurred Message=The parameters dictionary contains a null entry for parameter 'communityId' of non-nullable type 'System.Int32' for method"
The communityMembership DTO gets deserialized and set properly, but neither URI parameter works. Please confirm this is a major bug.
Other Web API Notes:
MikeWasson
Member
486 Points
78 Posts
Microsoft
Re: Put is definitely broken
Apr 05, 2012 05:26 PM|LINK
I'm not sure what the RegisterServiceRoute method is? But this route worked for me:
public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); routes.MapHttpRoute( name: "Community Membership1", routeTemplate: "communities/{communityId}/membership/{userId}", defaults: new { controller = "Membership" }, constraints: new { communityId = @"\d+", userId = @"\d+" } ); }I just tried it with this URL in Fiddler: .../communities/1/membership/2
Do you have other routes, or other PUT methods in the controller?
dgdev
Member
22 Points
18 Posts
Re: Put is definitely broken
Apr 05, 2012 06:54 PM|LINK
RegisterServiceRoute is part of my application web api bootstrapper. (NContext) Essentially it just registers a route that will later be added to the routing table.
----------------------------------------------------
dgdev
Member
22 Points
18 Posts
Re: Put is definitely broken
Apr 06, 2012 01:59 PM|LINK
This is within a MVC 3 Web Application. To narrow the potential causes, I've removed all other routes except for:
I'm still having the same problem.
khaihon
Member
4 Points
2 Posts
Re: Put is definitely broken
Apr 06, 2012 05:39 PM|LINK
Check out my response in http://forums.asp.net/p/1776856/4920013.aspx/1?p=True&t=634693162583908581
Make sure you are using .Net Framework 4 and not 4.5.
dgdev
Member
22 Points
18 Posts
Re: Put is definitely broken
Apr 06, 2012 07:01 PM|LINK
Thanks for your input. I'm running on .NET 4 however, using the NuGet packages for Web API.
dgdev
Member
22 Points
18 Posts
Re: Put is definitely broken
Apr 10, 2012 08:14 PM|LINK
After a couple more hours of debugging, I finally figured out my problem. Don't clear your formatters!
I had been using Web API since WCF Preview 2 or 3 and this used to be ok to do. Hope this helps!
pvasek
Member
4 Points
6 Posts
Re: Put is definitely broken
Apr 16, 2012 07:53 AM|LINK
You save my day :)
BTW: It is not just about clearing the formatters collection but about removing the standard json formatter. It seems that the standard json formatter just need to be included in the formatters collections.
tj_moore
Member
10 Points
6 Posts
Re: Put is definitely broken
May 17, 2012 03:14 PM|LINK
Wow, thanks! Not clearing the formatters fixed this for me too.
Been scratching my head for ages especially as it was working before but at some point I'd read about clearing the formatters and hadn't spotted it had broken this (note to self - improve the test suite to pick this up!).