Xamarin Forms Azure error

0

I am trying to connect an application of Xamarin Forms with Microsoft Azure and at the moment of compiling I display the following error:

Method 'System.Net.Http.HttpClientHandler.set_AutomaticDecompression' not found.

Azure Client:

using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.WindowsAzure.MobileServices;
namespace Catcher
{
    public class AzureClient
    {

        private IMobileServiceClient client;
        private IMobileServiceTable<Registro> table;

        public AzureClient()
        {

            client = new MobileServiceClient("http://catcher.azurewebsites.net");
            table = client.GetTable<Registro>();

        }

        public Task<IEnumerable<Registro>> GetUsers() {

            return table.ToEnumerableAsync();

        }

    }
}

Registro.cs

    using System;
using Microsoft.WindowsAzure.MobileServices;
using Newtonsoft.Json;

namespace Catcher
{
    [DataTable("users")]
    public class Registro
    {

        [JsonProperty("user")]
        public string user { get; set; }

        [JsonProperty("password")]
        public string password { get; set; }

    }
}

registro_page.xaml.cs

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Xamarin.Forms;

namespace Catcher
{
    public partial class Registro_Page : ContentPage
    {

        private AzureClient client;
        public ObservableCollection<Registro> users { get; set; }
        public Command RefreshCommand { get; set; }

        public Registro_Page()
        {
            users = new ObservableCollection<Registro>();
            RefreshCommand = new Command(() => Load());
            client = new AzureClient();
            InitializeComponent();
        }

        public async void Load() {

            IsBusy = true;
            users.Clear();

            var result = await client.GetUsers();

            foreach (var user in result) {

                users.Add(user);

            }

            IsBusy = false;

        }

    }
}

app.xaml.cs

using Xamarin.Forms;

namespace Catcher
{
    public partial class App : Application
    {

        private Registro_Page registroPage;

        public App()
        {   
            InitializeComponent();

            registroPage = new Registro_Page();
            MainPage = new Registro_Page();
        }

        protected override void OnStart()
        {
            // Handle when your app starts
            registroPage.Load();
        }

        protected override void OnSleep()
        {
            // Handle when your app sleeps
        }

        protected override void OnResume()
        {
            // Handle when your app resumes
        }
    }
}
    
asked by Gustavo Serna 29.12.2016 в 07:13
source

1 answer

1

The error commonly occurs when the NuGet libraries of the Microsoft.Net.HttpClient packages, which are used for HTTPS / REST operations with Xamarin, have not been correctly imported. This package must be installed correctly both in the PCL and in the specific projects of each platform before making any type of HTTP connection.

    
answered by 06.01.2017 в 19:45