Thursday, February 9, 2017

Xamarin Forms and Azure Easy Tables (as easy as 1 2 3)

Overview


Hi Guys, we are about to discuss Xamarin.Forms with Azure Appservices Easy Tables, great front-end apps need great back-end and there is tons of solution or options of doing it, But today we will see how Azure has done a great job making it relatively easy for developers to connect on back-end service without coding it.



Getting Started


Now lets create a Mobile App Service in Azure Portal, Go ahead by clicking "Mobile App" as shown in a screenshot below.





Now click create.






Name your app accordingly, in our case we named it "conversationapp". If you have no existing resource you can create new one or you can use your existing one. Now click create.





Now click "Easy Tables" in order for us to create table.






You will notice that, you will need to configure your easy tables as it has detected that no database has been created for use in your easy tables.







Now click the highlighted link below to create a new database.







Click add to create database.










Now name your database, in our example we name it "conversationdb".







You can select pricing accordingly, in our case we use free since this is for testing purpose. But in production we should use a more appropriate capacity according to our app's scaling need.







We also gonna need to create a server for our db, in our case we use the location "East Asia".






When you are done with creating a database, you are now ready to initialize App Service to use easy tables. Now click Initialize App.






Now go and create a table named "Message", we make it more simple as possible. You can create as many tables depending on your app. We can also set table relationship when it needs to, be aware to editing deleting columns created by Azure tables that might cause an issue with syncing.





And that's it for the App Service.




Creating our app to Connect With Easy Tables


Now that our app service is ready to rock in roll, we can now create our app to connect with easy tables. First create a new Xamarin.Forms project and name it "ConversationApp".






Create model for Message


- -


Creata ViewModel for ConversationPage and name it "ConversationPageViewModel"


- -


Create a new Page and name it ConversationPage.xaml






- -


Now create our AzureService client class to make a sync calls to our easy tables, but before that, we will need to install nuget packages for MobileServiceClient in our PCL and Platform projects as shown below.






Initialize the Azure Mobile Client



Add the Azure Mobile Client SDK initialization code in the platform projects. For iOS, the following code must be added to the FinishedLaunching method of the AppDelegate class:

Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();
SQLitePCL.CurrentPlatform.Init();



For Android, add the following to the OnCreate method of your MainActivity:

Microsoft.WindowsAzure.MobileServices.CurrentPlatform.Init();


We will now create AzureDataService , the following are the code



- -



We will now be able to run our Xamarin project, please make sure to make platform project as a startup. It should look like this.






You should be able to see the data you sync in Azure Easy Tables, without a sweat :D


Please check the full source code here.


Wrapping Up

Azure App Services provides more flexibility for mobile development integrating Authentication, Notification and that what makes it a developer centric tool. To learn more of this please check our Xamarin Blog  https://blog.xamarin.com . Please dont hesitate to leave a message if you have clarification or question. Thats all.











5 comments:

  1. So if we have multiple tables, do we create multiple 'AzureDataService' classes and name them such as classNameAzureDataService?

    Evidently the sync calls and insert/get calls a table specific. In other words, how do we handle multiple tables, especially if there will be many tables.

    Thanks!

    ReplyDelete
  2. nice blog has been shared by you.before i read this blog i didn't have any knowledge about this but now i got some knowledge. so keep on sharing such kind of an interesting blog.
    xamarin development company
    hire xamarin developer india

    ReplyDelete