Home > Software design >  AmbiguousMatchException: The request matched multiple endpoints. Matches?
AmbiguousMatchException: The request matched multiple endpoints. Matches?

Time:11-23

I'm writing .Net Core WebAPI, here I'm writing Two HttpGet methods one is to fetch all records irrespective of params, and another one is with param(around 25 params), but I'm getting AmbigousMatchException error.

How i can resolve this ?

enter image description here

below is the code.

[Route("api/[controller]")]
[ApiController]
public class SummaryReportController : Controller
{
    DataProvider dp = new DataProvider();

    private readonly IConfiguration _configuration;
    public SummaryReportController(IConfiguration configuration)
    {
        _configuration = configuration;
    }

    [HttpGet]
    public JsonResult GetSummaryReport()
    {
        dp.ConnectionString = _configuration.GetConnectionString("conAccounting_SQLWeb");

        DataSet ds = new DataSet();
        ds = dp.GetDataSetSProc("uspFreight_SearchFreight");

        DataTable dt = ds.Tables[0];

        return new JsonResult(dt);
    }

    [HttpGet]
    public JsonResult GetSummaryReportWithParams(SummaryReport sm)
    {
        dp.ConnectionString = _configuration.GetConnectionString("conAccounting_SQLWeb");

        DataSet ds = new DataSet();
        SqlParameter[] paramChk = new SqlParameter[21];
        paramChk[0] = new SqlParameter("@VendIDName", sm.VendID);
        paramChk[1] = new SqlParameter("@BOLNumber", sm.BOLNumber);
        paramChk[2] = new SqlParameter("@BOLWeightFrom", sm.BOLWeightFrom);
        paramChk[3] = new SqlParameter("@BOLWeightTo", sm.BOLWeightTo);
        paramChk[4] = new SqlParameter("@InvoiceAmtFrom", sm.InvoiceAmountFrom);
        paramChk[5] = new SqlParameter("@InvoiceAmtTo", sm.InvoiceAmountTo);
        paramChk[6] = new SqlParameter("@DistanceFrom", sm.DistanceFrom);
        paramChk[7] = new SqlParameter("@DistanceTo", sm.DistanceTo);
        paramChk[8] = new SqlParameter("@InvoiceDateFrom", sm.InvoiceDateFrom);
        paramChk[9] = new SqlParameter("@InvoiceDateTo", sm.InvoiceDateTo);
        paramChk[10] = new SqlParameter("@ShipmentDateFrom", sm.ShipmentDateFrom);
        paramChk[11] = new SqlParameter("@ShipmentDateTo", sm.ShipmentDateTo);
        paramChk[12] = new SqlParameter("@ShipperZip", sm.ShipperZip);
        paramChk[13] = new SqlParameter("@ConsigneeCityState", sm.ConsigneeCityState);
        paramChk[14] = new SqlParameter("@ConsigneeZip", sm.ConsigneeZip);
        paramChk[15] = new SqlParameter("@ConsigneeCode", sm.ConsigneeCode);
        paramChk[16] = new SqlParameter("@ConsigneeName", sm.ConsigneeName);
        paramChk[17] = new SqlParameter("@WhseID", sm.WhseID);
        paramChk[18] = new SqlParameter("@LTLFTL", sm.LTLFTL);
        paramChk[19] = new SqlParameter("@TRSO", sm.TRSO);
        paramChk[20] = new SqlParameter("@FTL", sm.FTL);
        ds = dp.GetDataSetSProcWithProc("uspFreight_SearchFreight", paramChk);

        DataTable dt = ds.Tables[0];

        return new JsonResult(dt);
    }

}

CodePudding user response:

Try to change [Route("api/[controller]")] to [Route("api/[controller]/[action]")] Then the default route of actions in SummaryReportController will be api/SummaryReport/{actionname}.You can refer to the official enter image description here

CodePudding user response:

Add the parameter to the route for the second endpoint [HttpGet("{sm}")]

  • Related