Xamarin Forms with Azure

Asked

Viewed 102 times

0

I am creating an application with integration with Azure, when I try to instantiate the MobileServiceClient I have the following exception

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

Here’s the definition of my class

public class AzureClient
{
    private IMobileServiceClient _client;
    private IMobileServiceSyncTable<Contact> _table;
    private const string serviceUri = "http://{app}.azurewebsites.net/";
    const string dbPath = "contactDb";

    public AzureClient()
    {
        _client = new MobileServiceClient(serviceUri);

        var store = new MobileServiceSQLiteStore(dbPath);
        store.DefineTable<Contact>();
        _client.SyncContext.InitializeAsync(store);

        _table = _client.GetSyncTable<Contact>();
    }

    public async Task<IEnumerable<Contact>> GetContacts()
    {
        var empty = new Contact[0];
        try
        {
            if (Plugin.Connectivity.CrossConnectivity.Current.IsConnected)
                await SyncAsync();
            return await _table.ToEnumerableAsync();
        }
        catch (Exception)
        {
            return empty;
        }
    }

    public async void AddContact(Contact contact)
    {
        await _table.InsertAsync(contact);
    }

    public async Task SyncAsync()
    {
        ReadOnlyCollection<MobileServiceTableOperationError> syncErrors = null;

        try
        {
            await _client.SyncContext.PushAsync();

            await _table.PullAsync("allContacts", _table.CreateQuery());
        }
        catch (MobileServicePushFailedException pushEx)
        {
            if (pushEx.PushResult != null)
                syncErrors = pushEx.PushResult.Errors;
        }
    }

    public async Task CleanData ()
    {
        await _table.PurgeAsync("allContacts", _table.CreateQuery(), new System.Threading.CancellationToken());
    }
}

The error happens when I try to run the project for Android. The complete project source code is in my github

  • I was going to do this marathon, but I’m in no condition at the moment. I’m wanting to learn Xamarin too.

  • It’s been a marathon anyway. But it is being very profitable the good that I will have carnival holidays and will give to research more about these problems.

1 answer

0


I’m also doing the marathon.

You added the HTTP client reference to your projects (including PCL) ?

If not, try adding and see if the problem continues.

  • Well, I believe I had to give a clean and build on the project, or even close and open the VS, because I left and came home and it worked.

  • ..rs.. sometimes happens to.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.