Demo Cloud

Demo Cloud

  • NA
  • 140
  • 12k

How to consume the web api in xamarin forms?

Dec 1 2020 11:10 PM
Hello,
 
Below is the code for web api, I wanted to consume/call the web api in xamarin forms and bind the result to the picker.
  1. [System.Web.Http.HttpGet]  
  2. public HttpResponseMessage GetNames()  
  3. {  
  4. //Conectionstrings for different databases  
  5. string client1 = ConfigurationManager.ConnectionStrings["client_db1"].ConnectionString;  
  6. string client2 = ConfigurationManager.ConnectionStrings["client_db2"].ConnectionString;  
  7. string client3 = ConfigurationManager.ConnectionStrings["client_db3"].ConnectionString;  
  8. //Applying the select command for different databases  
  9. SqlConnection con = new SqlConnection(client1);  
  10. SqlDataAdapter da1 = new SqlDataAdapter("select provider_name,Id from Provider_details", con);  
  11. DataSet ds1 = new DataSet();  
  12. da1.Fill(ds1);  
  13. con = new SqlConnection(client2);  
  14. da1.SelectCommand.Connection = con;  
  15. DataSet ds2 = new DataSet();  
  16. da1.Fill(ds2);  
  17. con = new SqlConnection(client3);  
  18. da1.SelectCommand.Connection = con;  
  19. DataSet ds3 = new DataSet();  
  20. da1.Fill(ds3);  
  21. //Merging the database to select the provider name  
  22. ds1.Merge(ds2);  
  23. ds1.Merge(ds3);  
  24. return Request.CreateResponse(HttpStatusCode.OK, ds1);  
  25. }  
Please help me,
Thanks

Answers (12)