Mar 19, 2013

ASP.NET 4.5 WEB API with Fiddler2

During my learning ASP.NET 4.5 WEB API I've spent too much time on one glich.
Here is my API controller action:

public DummyWrapper Post(DummyWrapper dummy)
        {            
            return "success";
        }



I was trying using Fiddler2 to emulate POST request:


User-Agent: Fiddler

Content-Type: application/json; charset=utf-8

Host: localhost:1600

Content-Length: 40


 {"dummy":{"value":"This is the title"}}

Initial version of my POCO on WEB API service


 public class DummyEntity
            {
                public string value { get; set; }
            }


I could not make Action model binder to deserialize above json object to dummy POCO.
After some time it hit me.
The catch was to wrap up entity in wrapper class.



 public class DummyWrapper
        {
            public DummyEntity dummy { get; set; }
           public class DummyEntity
            {
                public string value { get; set; }
            }
        }  

No comments:

Post a Comment