0
votes

API

[RoutePrefix("api/diagnostics")]
public class DiagnosticsController : ApiController
{
    [HttpPost]
    [Route("pings")]
    public IHttpActionResult Pings(Ping ping)
    {

    }
}

Ping

public class Ping
{
   public Guid ServerKey {get;set;}
   public DateTime CreatedDateTime {get;set;}
}

I am trying to test the class using Postman application. Here is the Screenshot.

The message I get back is:

{
"message": "No HTTP resource was found that matches the request URI 'http://localhost:61668/api/diagnostics/pings'.",
"messageDetail": "No action was found on the controller 'Diagnostics' that matches the request."
}

I am failing to understand why it does not match the post action in Diagnostics controller. The only other route configured is the default route:

 config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{key}",
                defaults: new { key = RouteParameter.Optional }
            );

Also attribute routing is enabled: config.MapHttpAttributeRoutes();

1
Look very closely at the URL you're querying. The screenshot does not correspond with your error message. If that is a minor oversight: you're absolutely sure your local server is running the moment you send the request? If you stop debugging, the host will be gone as well. - Jeroen Vannevel
@Jeroen That was an oversight. I have posted the screennshot again. Yes the server is running. - souser
I don't see why your code shouldn't work then. Have you narrowed the problem down somehow? Does it work if your method doesn't take a Ping object? Consider using nullable values rather than Guid/DateTime. Can you create a new project with these classes as a bare minimum and does it work then? - Jeroen Vannevel

1 Answers

0
votes

Try to mark your parameter with [FromBody] attribute - public IHttpActionResult Pings([FromBody] Ping ping).