Driver with two post methods in a web api

0

I'm doing an api web service with c #. In a controller I need to have two post methods.

Right now, I have something like this.

 public class TramitesController : ApiController
    {
    [ResponseType(typeof(Tramite))]
    [BasicAuthenticationFilter]
    public IHttpActionResult PostTramite(Tramite tramite)
      {
      return null;
	  }
			
    [ResponseType(typeof(Incidencia))]
    [BasicAuthenticationFilter]
    public IHttpActionResult PostTramite(Incidencia incidencia)
      {
      return null;
      }
    }

If I mention one or the other method, it works correctly, but both at the same time, it does not, it gives an error.

Is it possible to have more than one post method?

Thanks

    
asked by Juanjo 09.01.2018 в 19:59
source

1 answer

2

You should give it a different route, either by moving one of the actions to a new controller, or by indicating a different route through a RouteAttribute attribute:

public class TramitesController : ApiController
{
[ResponseType(typeof(Tramite))]
[BasicAuthenticationFilter]
public IHttpActionResult PostTramite(Tramite tramite)
  {
  return null;
  }

[ResponseType(typeof(Incidencia))]
[BasicAuthenticationFilter]
[Route("Incidencia")]
public IHttpActionResult PostTramite(Incidencia incidencia)
  {
  return null;
  }
}

This way, the first action would have the default route of the controller (if you left the configuration of routes by default it would be http://rutaAplicacion/api/Tramites ) and the second one adding to the route Incidencia ( http://rutaAplicacion/api/Tramites/Incidencia ).

    
answered by 10.01.2018 / 13:16
source