i have following APi Controller
public class TriggerController : ApiController
{
[HttpPost]
[ActionName("fileimport")]
public int CreateFileImportTrigger([FromBody]ITrigger _object)
{
return scheduler.CreateFileImportTrigger(_object);
}
.....
...
My WEbApiConfig is like so and the call matches the third route.
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "ApiById",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional },
constraints: new { id = @"^[0-9]+$" }
);
config.Routes.MapHttpRoute(
name: "ApiByName",
routeTemplate: "api/{controller}/{action}/{name}",
defaults: null,
constraints: new { name = @"^[a-z]+$" }
);
config.Routes.MapHttpRoute(
name: "ApiByAction",
routeTemplate: "api/{controller}/{action}",
defaults: new { _object = RouteParameter.Optional }
);
var appXmlType = config.Formatters.XmlFormatter.SupportedMediaTypes.FirstOrDefault(t => t.MediaType == "application/xml");
config.Formatters.XmlFormatter.SupportedMediaTypes.Remove(appXmlType);
}
The ITrigger is defined as so.
public interface ITrigger
{
string Name{ get; set; }
string FilePath{ get; set; }
string TriggeredJobEntityCode{ get; set; }
int ID{ get; set; }
TriggerTypes Type{ get; set; }
string SubmitDate{ get; set; }
DateTime SubmitTime{ get; set; }
IJob[] Jobs { get; set; }
}
and
I have specified in the Http Header the Content-Type as application/json
the body i am posting is like so
{
"Name": "FileEventTrigger",
"FilePath": "C:\\Users\\file.txt",
"TriggeredJobEntityCode": null,
"Jobs": [
{
"ID": 1643,
"TemplateID": 1643,
"Name": "SomeJob",
"SubmitToRunTime": "0001-01-01T00:00:00",
"Parameters": [
{
"Name": "Seconds",
"Value": "30",
"DefaultValue": "30",
"isRequired": true,
"DataType": "Integer"
}
]
}
],
"ID": 1,
"Type": 0,
"SubmitDate": "7/21/2013",
"SubmitTime": "0001-01-01T00:00:00"
}
I have a break point at the beginnning of the CreateFileImportTrigger method where i check the value of the _object and it shows up "null" after i post the call. So somewhere the WebApi application is not reading the body and serializing it to _object parameter. The service is returning ITrigger object fine only is not able to handle POST.
Any help would be appreciated.
Thanks