Rahul Patil

Rahul Patil

  • 1.9k
  • 37
  • 605

issue with webapi in mvc

Aug 6 2020 4:18 AM

now I am working on webapi but I am getting an error : The remote certificate is invalid according to the validation procedure in mvc

first I create a webapi project this is project url : https://localhost:44362/api/emps

empsController.cs

  1. public class empsController : ApiController    
  2. {    
  3.    private empdbEntities db = new empdbEntities();    
  4.     
  5.    // GET: api/emps    
  6.    public IQueryable<emp> Getemps()    
  7.    {    
  8.        return db.emps;    
  9.    }  
  10. } 
 
 
second I create a another project for performing a crud operation
 
empsController.cs
  1. public class empsController : Controller    
  2. {    
  3.      // GET: emps    
  4.      public JsonResult Index()    
  5.      {    
  6.          IEnumerable<mvcempmodel> empList;    
  7.          HttpResponseMessage response = globalvariable.webapiclient.GetAsync("emps").Result;    
  8.          empList = response.Content.ReadAsAsync<IEnumerable<mvcempmodel>>().Result; //this line give an error    
  9.          return Json(empList,JsonRequestBehavior.AllowGet);    
  10.      }    
  11. }
mvcempmodel.cs
  1. public class mvcempmodel  
  2.  {  
  3.     public int empid { get; set; }  
  4.     public string empname { get; set; }  
  5.     public string empaddress { get; set; }  
  6. }  
globalvariable.cs
  1. public static class globalvariable  
  2. {  
  3.     public static HttpClient webapiclient = new HttpClient();  
  4.   
  5.     static globalvariable()  
  6.     {  
  7.         webapiclient.BaseAddress = new Uri("https://localhost:44362/api/");  
  8.         webapiclient.DefaultRequestHeaders.Clear();  
  9.         webapiclient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));  
  10.     }  
  11. }  
here I get an error :
  1. empList = response.Content.ReadAsAsync<IEnumerable<mvcempmodel>>().Result; //this line give an error 
 
 
how to solve this error?
 
help

Brought to you by:

Answers (2)