Which is the best and easiest way to connect xamarin.forms with external database ?

OmarMohOmarMoh USMember ✭✭

Hello Xamarin dev's

I'm trying to building my project graduation using xamarin.form , The problem is in the past i was use .asmx web service to consuming with xamarin.form project but now it doesn't work as before so, please if someone can help me becouse i just have 9 weeks to finish the whole project .
note that if there is a way that able to communicate and read PHP files it will be helpful .

waiting for response and thanks for all

Best Answer


  • OmarMohOmarMoh USMember ✭✭

    @LuisDavidDelaCruz Thanks for reply , i started my first Web API Project that connected with Mysql DB using Mysql.data NuGet package, i tested the connection using GET method in controller and it's work, now how can i use POST method to insert data to my database ?
    the HTTP method is look like the following
    public void Post([FromBody]string value) { }

  • LuisDavidDelaCruzLuisDavidDelaCruz Member ✭✭✭
    edited October 9

    Hi @OmarMoh I recommend you to do something like this in case you send many elements to insert
    in your WEB API:
    public string InicioSesionP1([FromBody]YourClass class)
    //Do Everithing to insert

    In your Xamarin.Forms app using HttpClient

        var dataUser= new YourModel
        name ="Luis David",
        Lasname = "De La Cruz"};
         var stringPayload = JsonConvert.SerializeObject(dataUser);
        using (var client = new HttpClient())
        client.BaseAddress = new Uri("https://yourdomain.com");
        var content = new StringContent(stringPayload, Encoding.UTF8, "application/json");
        var result = await client.PostAsync("yourmethod", content);
        string resultContent = await result.Content.ReadAsStringAsync();
        await Application.Current.MainPage.DisplayAlert("Message","Data inserted","Ok");
Sign In or Register to comment.