github can alert you and call your webservice when commits are pushed to a repository (Post-Receive Hooks). github sends the commit information as JSON but inside a form encoded parameter. That is, the content type is application/x-www-form-urlencoded and the http request is
POST /my_uri HTTP/1.1
Content-Type: application/x-www-form-urlencoded
payload=%7B%22ref%22%3A%22refs%2Fheads...
I want to write the webservice that processes the new commits in ASP.NET MVC or WebAPI. I've defined some classes to deserialize the json, but I can't get the framework to initialize my objects directly. What I have now is
public string my_uri(string payload)
{
var s = new JavaScriptSerializer();
var p = s.Deserialize(payload, typeof(Payload)) as Payload;
...
}
but I would want
public string my_uri(Payload payload)
{
...
}
I've read about ValueProviders but I didn't find a way to chain them. I need to compose FormValueProviderFactory and JsonValueProviderFactory. How can I get ASP to do the binding?