Anand
Anand

Reputation: 1959

No resource found error while calling WEB API

I created a WEB API for getting some list . I created another API for login which is working fine. But whenever call the API which provide me some list, it will show error as No HTTP resource was found that matches the request URI 'http://localhost:85476/API/EmployeeMobile/GetEmployeeForMobile, No action was found on the controller 'EmployeeMobile' that matches the request.

My controller:

 public class EmployeeMobileController : ApiController
    {

        private PCommon _pCommon;
        IEmployeeBusiness _employeeBusiness;
        Mapper _mapper;
        public EmployeeMobileController()
        {
            _pCommon = new PCommon();
            _employeeBusiness = new EmployeeBusiness();

            _mapper = new Mapper();
        }

        [HttpPost]

        public string GetEmployeeForMobile(string userID, string connectionString)
        {
            DataSet dsEmployee = _employeeBusiness.GetAllEmployeeForMobile(Guid.Parse(userID), connectionString);
            JavaScriptSerializer json_serializer = new JavaScriptSerializer();
            object routes_list = (object)json_serializer.DeserializeObject(JsonConvert.SerializeObject(dsEmployee.Tables[0]));
            return JsonConvert.SerializeObject(routes_list);
        }
    }

My WebApiConfig.cs

public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            config.MapHttpAttributeRoutes();
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );


        }
    }

My PostMan Calling details

http://localhost:61557/API/EmployeeMobile/GetEmployeeForMobile

Body: {"userID":"fc938df0-373c559f","connectionString":"Data\tSource=WIN\\MSSQLSERVER2016;Initial\tCatalog=PDefault;User\tID=db;Password=db123"}

Please help me to recover this problem.

Upvotes: 1

Views: 742

Answers (1)

PSK
PSK

Reputation: 17943

Please note, WebAPI doesn't support binding of multiple POST parameters. You are defining your POST like a GET method. Change it to return a single Model

Your model should look like following.

 public class Input
    {
        public string uSerID { get; set; }
        public string connectionString { get; set; }
    }

Now change the POST method like

 [HttpPost]
 public string GetEmployeeForMobile(Input request)
  {
   //Your implementation here
  }

and you JSON for the post should look like following.

{uSerID:"abc", connectionString :"xyz"}

Upvotes: 1

Related Questions