API linking Database to MVC project and Mobile App Xamarin API linking Database to MVC project and Mobile App Xamarin azure azure

API linking Database to MVC project and Mobile App Xamarin


Firstly

For the error that appears: missing an assembly or reference.

The HttpClient lives in the "System.Net.Http" namespace.

You'll need to add: using System.Net.Http;

as mentioned here


secondly

is there a better way to allow your Db to communicate with both your MVC project and mobile app?

yes there is better way,after publish your MVC Project,

you can use Azure Mobile Client.

  • step 1

Open "Package Manager Console" and type

Install-Package Microsoft.Azure.Mobile.Client -Version 4.0.2

or you can get the last version from Azure Mobile Client SDK

This library provides features for creating Windows and Xamarin mobile apps that connect to Azure Mobile Apps

  • step 2

assume you have a class called "user",and you want to read, insert, update and delete data

take a look at the following code example:

using Microsoft.WindowsAzure.MobileServices;using System.Collections.ObjectModel;using System.Threading.Tasks; public class User {/*....*/ }  public class AzureServices  {      private static readonly string url = "http://xxxxx.azurewebsites.net";      /*       * The Azure Mobile Client SDK provides the MobileServiceClient class,        * which is used by a Xamarin.Forms application to access the Azure Mobile Apps instance      */      public MobileServiceClient Client;      public IMobileServiceTable<User> UserTable;      public AzureServices()      {          /*            * When the MobileServiceClient instance is created,           * an application URL must be specified to identify the Azure Mobile Apps instance.          */          Client = new MobileServiceClient(url);          //calling the GetTable method on the MobileServiceClient instance, which returns a IMobileServiceTable<User> reference.          UserTable = Client.GetTable<User>();      }      // Querying Data      public async Task<ObservableCollection<User>> GetAllUsers(bool sync = false)      {          var userList = await UserTable.ToEnumerableAsync();          return new ObservableCollection<User>(userList);      }      //Inserting Data      public async Task AddUser(User item)      {          await UserTable.InsertAsync(item);      }      // Updating Data      public async Task UpdateUser(User item)      {          await UserTable.UpdateAsync(item);      }      // Deleting Data      public async Task DeleteUser(User item)      {          await UserTable.DeleteAsync(item);      }  }

For more information visit Azure Mobile App