Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am working on web api project. i am totally new for web api project. i have two controller namely Inventory and Customer. in both controller, a get method with same number of parameter but method name are different. below are controller method details with parameter.
Inventory controller method signature is:
C#
[System.Web.Http.HttpGet]
       [System.Web.Http.ActionName("GetByPara")]
       public IEnumerable<Inventory> GetInventoryByParamas(string IP, string Port, string CompanyName, string UserName, string Password, string Item, string Description, string Price)

{
}

and Customer controller method signature is:
C#
[System.Web.Http.HttpGet]
[System.Web.Http.ActionName("custbyparam")]
       public IEnumerable<Customer> GetCustomerByParams(string IP, string Port, string CompanyName, string UserName, string Password, string CustomerName, string city, string Phone1)

{
}
and i defined the route for both controller in webapiconfig.cs file, and also define the default route, which is below: just see the routes.
C#
public static void Register(HttpConfiguration config)
       {
//default route:
           config.Routes.MapHttpRoute(
               name: "ActionApi",
               routeTemplate: "api/{controller}/{action}/{id}",
               defaults: new { id = RouteParameter.Optional }
           );


//Inventory route
C#
config.Routes.MapHttpRoute(name: "InventoryParams", routeTemplate: "api/{Controller}/{action}/{IP}/{Port}/{CompanyName}/{UserName}/{Password}/{Item}/{Description}/{Price}");


//Customer route
C#
config.Routes.MapHttpRoute(name: "CustomerParams", routeTemplate: "api/{controller}/{action}/{IP}/{Port}/{CompanyName}/{UserName}/{Password}/{CustomerName}/{city}/{Phone1}");

}
i write the Inventory route on top of customer route, and pass the parameter in url:
http://localhost:55024/api/Inventory/GetByPara/192.168.1.131/5555/Spearpointlocal/admin/syspro15StarTX/100-10100-CI/Coin%20Wrappers%20-%20SBA%20Dollar%20and%20Canadian%20Loonies%20-Custom%20Imprint/7[^]

but when i write the Inventory route bottom on customer route it's not working while i pass the same url. i got the error the page cannot be found(HTTP 404 not found).

and vice-versa for customer route and passing the url for customer.


please guys help me,
thanks in advance.
please please help.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900