I'm still looking for help regarding below issue:
I've been working on a RESTful API in a MVC C#.NET (4.0) Web API project for my companies over a few days now (on and off) but for some reason I can't seem to get the API to route to the HTTP POST, but keeps on defaulting to Get (I'm assuming..).
I've got a few GET requests working fine, I've even stress-tested them, this leads me to believe there is a routing error somewhere that I can't seem to find...
I get this error message when navigating to (I've tried many other parameters too, but the debugger won't catch the Post method firing).
{"Message":"The requested resource does not support http method 'GET'."} localhost:61090/api/Ole_foundations/Post/?s=kalle
This is my Post:
[HttpPost]
public void Post(string s)
{
WSC.DNN.WorksiteCloudOLEDC.WorkSiteCloudOLEDC.WorkSiteCloudOLEDC wdc = new WSC.DNN.WorksiteCloudOLEDC.WorkSiteCloudOLEDC.WorkSiteCloudOLEDC();
int ret1 = 0;
int ret2 = 0;
Boolean ret3 = wdc.INSERTOLE_Foundation(14774, 14774, "JSONTEST", "JSONTEST", "JSONTEST", 0.00, 0.00, 0.00, 0.000, 0.00, 0.000, "JSONTEST", 0.000, 0.000, 12345, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, "JSONTEST", 1234, 0.000, 0.000, 0.000, 0.000, true, true, Convert.ToDateTime("01/01/1900"), "JSONTEST", "JSONTEST", true, "JSONCOMMENTTEST", 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, true, true, true, true, true, true, true, 12345, true, true, 12345, true, true, "JSONTEST", "JSONTEST", "JSONTEST", null, Convert.ToDateTime("01/01/1900"), "JSONTEST", null, Convert.ToDateTime("01/01/1900"), Convert.ToDateTime("01/01/1900"), Convert.ToDateTime("01/01/1900"), null, null, null, true, true, true, "JSONTEST", 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, null, "FINALJSONTEST", true, "NRCJSONTEST", 12345, true, true, true, true, true, true, "UPDATEDBYTEST", 3322, WSC.DNN.GeneralRoutines.clsEnums.MappingTypes.OLE_Foundation, conStr, "JoakimJSONTEST", ref ret1, ref ret2);
}
Everything in the method-body is fine and works as intended.
These are the routes as defined in WebApiConfig.cs:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{parameters}",
defaults: new { parameters = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "ApiByAction",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { controller = "Ole_foundations", action = "GetFromThreads", id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "insertRoute",
routeTemplate: "api/{controller}/{action}/{param}",
defaults: new { controller = "Ole_foundations", action = "Post", param = RouteParameter.Optional }
);
And these are the routes defined in **Global.asax.cs:**
public class WebApiApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
RouteTable.Routes.MapHttpRoute(null, "api/{controller}/{action}/{parameters}",
new { parameters = UrlParameter.Optional, Action = "Get" });
RouteTable.Routes.MapHttpRoute(null, "api/{controller}/{action}/{param}",
new { Action = "Post", param = UrlParameter.Optional });
}
}