Reputation: 2235
I'm adding methods to an additional Web API controller. Testing out one of the existing methods I'm able to hit my break points. Yet if I try to call into one of the new ones I get a 404. I'm testing locally using IIS Express and Postman. Examples below, any idea what could cause this?
When I try to call the new endpoint this is the response I receive:
{"Message":"No HTTP resource was found that matches the request URI 'http://localhost:53453/api/nisperson/addnewconnection'.",
"MessageDetail":"No action was found on the controller 'NISPerson' that matches the request."}
Existing method:
[HttpPost]
[ActionName("register")]
public ClientResponse PostRegisterPerson(HttpRequestMessage req, PersonModel person)
{
// This method is getting hit if I call it from Postman
}
endpoint : http://localhost:53453/api/test/register
Newly Added Method:
[HttpPost]
[ActionName("addnewconnection")]
public ClientResponse PostNewConnection(HttpRequestMessage req, string Email, String FirstName, string LastName)
{
// This is the new method which when called from Postman cannot be found.
}
Endpoint: http://localhost:53453/api/test/addnewconnection
Upvotes: 0
Views: 1609
Reputation: 3131
The reason is that it is expecting other parameters (simple string types) to be supplied in querystring which you are not supplying. So, it is trying to call Post with single parameter and failing to find it. Simple types are by default read from URI. If you want them to read from form body, use FromBody attribute.
Upvotes: 1
Reputation: 18265
You defined three required parameters in your method signature (Email
, FirstName
and LastName
):
[HttpPost]
[ActionName("addnewconnection")]
public ClientResponse PostNewConnection(HttpRequestMessage req, string Email, String FirstName, string LastName)
{
// This is the new method which when called from Postman cannot be found.
}
The route handler cannot map this URI: http://localhost:53453/api/test/addnewconnection
to your method because you are not providing those three required parameters.
The correct URI (leaving your method as is) is actually the following one:
http://localhost:53453/api/test/addnewconnection?Email=foo&FirstName=bar&LastName=baz
Either provide those parameters inside the URI as shown or turn them as not required providing a default value:
[HttpPost]
[ActionName("addnewconnection")]
public ClientResponse PostNewConnection(HttpRequestMessage req, string Email = null, String FirstName = null, string LastName = null)
{
// This is the new method which when called from Postman cannot be found.
}
Providing a default value will allow you to hit your method using your original URI.
Upvotes: 2