Forum Xamarin.Forms

How to bind or consume the below Web Api to Picker in Xamarin forms cross platform?

DemoCloudDemoCloud Member ✭✭✭

Hello,
How to consume the below web api in xamarin forms?
Below is the code for web api:
[System.Web.Http.HttpGet]
public HttpResponseMessage GetNames()
{

        //Conectionstrings for different databases
        string client1 = ConfigurationManager.ConnectionStrings["client_db1"].ConnectionString;
        string client2 = ConfigurationManager.ConnectionStrings["client_db2"].ConnectionString;
        string client3 = ConfigurationManager.ConnectionStrings["client_db3"].ConnectionString;


        //Applying the select command for different databases
        SqlConnection con = new SqlConnection(client1);
        SqlDataAdapter da1 = new SqlDataAdapter("select provider_name,Id from Provider_details", con);
        DataSet ds1 = new DataSet();
        da1.Fill(ds1);

        con = new SqlConnection(client2);
        da1.SelectCommand.Connection = con;
        DataSet ds2 = new DataSet();
        da1.Fill(ds2);

        con = new SqlConnection(client3);
        da1.SelectCommand.Connection = con;
        DataSet ds3 = new DataSet();
        da1.Fill(ds3);

        //Merging the database to select the provider name
        ds1.Merge(ds2);
        ds1.Merge(ds3);

        //return ds;
        return Request.CreateResponse(HttpStatusCode.OK, ds1);
    }

Please help me
Thanks

Answers

  • jezhjezh Member, Xamarin Team Xamurai

    If we want to communicate with the server, we need to know the request url of the webapi.

    For this, you can consult with the web api developers of your server.

    For how to communicate with different web services, you can check the official document:https://docs.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/web-services/

    Best Regards!


    Xamarin forums are migrating to a new home on Microsoft Q&A!
    We invite you to post new questions in the Xamarin forums’ new home on Microsoft Q&A!
    For more information, please refer to this sticky post.

  • DemoCloudDemoCloud Member ✭✭✭
    edited December 2020

    Hello, The url is shown below,
    http://192.168.0.108:8080/api/Multi_DB_Login/GetNames, code for web api is shared, i want to call it in xamarin forms,
    I'm not getting how to call a HttpResponseMessage web api.
    please help
    thanks

  • jezhjezh Member, Xamarin Team Xamurai

    Have you checked the official document Xamarin.Forms and Web Services?

    This article provides a walkthrough of the Xamarin.Forms sample application that demonstrates how to communicate with different web services. Topics covered include the anatomy of the application, the pages, data model, and invoking web service operations.

    If you read through above document, you should know how to call a HttpResponseMessage web api.

Sign In or Register to comment.