I'm hosting the Web-API using OWIN on a Azure Worker Role following this tutorials:
http://www.asp.net/web-api/overview/hosting-aspnet-web-api/use-owin-to-self-host-web-api http://www.asp.net/web-api/overview/hosting-aspnet-web-api/host-aspnet-web-api-in-an-azure-worker-role
The requests are being routed right. The break point stops as expected inside the controller method but the method parameter that is decorated with [FromBody] attribute, is always coming null.
Bellow are details of my methods and classes:
Request Header:
User-Agent: Fiddler
Content-Type: text/xml; charset=utf-8
Host: localhost:81
Content-Length: 365
Request body:
<?xml version="1.0"?>
<Unit name="ShopActiVID" serialNumber="00123" macAddress="40:d8:55:aa:aa:aa" tzOffset="-0400" useDst="True">
<Door name="Shop Main" ID="146">
<count date="2014-06-19T16:58:31.0000000Z" in="0" out="0"/>
</Door>
<Door name="Conf. Area" ID="147">
<count date="2014-06-19T16:58:31.0000000Z" in="2" out="0"/>
</Door>
</Unit>
Class used as payload for the body:
[DataContract(Name="Unit", IsReference=true)]
public class AddPeopleCountRequest
{
[DataMember(Name="name")]
public string Name { get; set; }
[DataMember(Name = "serialNumber")]
public string SerialNumber { get; set; }
[DataMember(Name = "macAddress")]
public string MacAddress { get; set; }
[DataMember(Name = "tzOffset")]
public string TzOffset { get; set; }
[DataMember(Name = "useDst")]
public bool UseDst { get; set; }
public List<Door> Doors { get; set; }
}
[DataContract(Name="Door", IsReference=true)]
public class Door
{
[DataMember(Name = "name")]
public string Name { get; set; }
[DataMember(Name = "ID")]
public int Id { get; set; }
public List<Count> Counts { get; set; }
}
[DataContract(Name="count", IsReference=true)]
public class Count
{
[DataMember(Name = "date")]
public DateTime Time { get; set; }
[DataMember(Name = "in")]
public int In { get; set; }
[DataMember(Name = "out")]
public int Out { get; set; }
}
Controller Method:
[RoutePrefix("api/v1")]
public class CollectorController : ApiController
{
[HttpPost]
[Route("count")]
public async Task<IHttpActionResult> AddPeopleCountRecord([FromBody]AddPeopleCountRequest addCountRequest)
{
...
return Ok();
}
}
OWIN Startup class:
public class Startup
{
public void Configuration(IAppBuilder app)
{
var config = new HttpConfiguration();
config.MapHttpAttributeRoutes();
app.UseWebApi(config);
}
}
So, every time I'm making the request on fiddler posting the XML, it never deserialize right into the Action parameter on the controller.
So what am I doing wrong?
Thanks! Really appreciate the help!