I have the following structure for my WEB API controller:
public class MyController : ApiController
{
[System.Web.Http.HttpPost]
public bool Method1([FromBody] int id, [FromBody] string token, [FromBody] string deviceID, [FromBody] string username)
{
bool returnValue = false;
//do code business logic here
return returnValue;
}
[System.Web.Http.HttpPost]
public bool Method2([FromBody] int id, [FromBody] string token)
{
bool returnValue = false;
//do code business logic here
return returnValue;
}
}
When I try to make a RESTFUL Web API over HTTP for either Method1
or Method2
, I get a 500 Internal Server Error.
If I remove the input parameters from either method, I have able to make the Web API without an error.
I have unit tested the controller through a .NET test method and the logic does not generate an exception.
I have added an additional method named Get
with no parameters, and was able to consume the service without any errors.
Here is a code snippet of me trying to consume the web API in JavaScript using jQuery:
var uri = "http://127.0.0.1/MyWebApi/api/mycontroller/method2";
var myObject =
{
id: $('#id').val(),
token: $('#token').val()
};
$.post(uri, JSON.stringify(myObject)).done(function (data) {
$('#result').text(data);
})
.fail(function (jqXHR, textStatus, err) {
$('#result').text('Error: ' + err);
});
What is causing me to get the 500 Internal Server Error on the initial API controller structure?