0

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();

3
  • 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. Commented May 11, 2015 at 23:15
  • @Jeroen That was an oversight. I have posted the screennshot again. Yes the server is running. Commented May 11, 2015 at 23:25
  • 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? Commented May 12, 2015 at 0:24

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

1 Comment

Can you try to delete you default route an leave only config.MapHttpAttributeRoutes();?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.