How to Create an Azure Back-End for a Xamarin.Forms Application - Part Two

Introduction

 
Welcome to the second part of the article on "How to create an Azure Back-End for a Xamarin.Forms Application".
 
In the first part of the article, we've seen how to create:
  • Resource Group
  • Web App
  • Azure SQL Database
  • Azure Server 
You can read the first part here.
 
In this second part, we'll see how to,
  • Deploy the SDK for .NET solutions to Azure.
  • Connect a basic ToDo application built with Xamarin.Forms to the Azure Back-End and the Azure SQL Database.
For simplicity, we'll use the code shared in the related GitHub repository by Microsoft.
 
Prerequisites
  • A Microsoft Azure Subscription (if you don't have one yet, see the Azure Portal for a free subscription).
  • Microsoft Visual Studio 2019 (all versions).
Step 1 - Add the connection string to the Web App. 
 
First of all, we have to add the Azure SQL Database connection string to the Web App.
  • Login into the Azure Portal with your credentials.
  • Click on the name of the Web App (Type App Service)
How To Create An Azure Back-End For A Xamarin.Forms Application
  •  Click on Configuration in the left-hand column.
How To Create An Azure Back-End For A Xamarin.Forms Application
  •  Click on New connection string
How To Create An Azure Back-End For A Xamarin.Forms Application
  • Compile the fields with the correct data and then click on save.
How To Create An Azure Back-End For A Xamarin.Forms Application
 
Step 2 - Deploy the SDK for .NET to Azure.
 
First, download the SDK for .NET, and the sample application from the related GitHub Repository.
  • https://github.com/Azure/azure-mobile-apps-quickstarts
 Now, we'll work on Visual Studio:
  •  Launch the IDE and select the folder we downloaded in the previous step.
How To Create An Azure Back-End For A Xamarin.Forms Application
  • In Solution Explorer, expand the tree, as shown in the following picture.
How To Create An Azure Back-End For A Xamarin.Forms Application
  • Open the ZUMOAPPNAME.sln solution and build it.
  • Right-click on ZUMOAPPNAMEService and select Publish.
How To Create An Azure Back-End For A Xamarin.Forms Application
 
 
  • Click on Start, then select App Service - Select Existing - Advanced.
How To Create An Azure Back-End For A Xamarin.Forms Application
 
How To Create An Azure Back-End For A Xamarin.Forms Application
  • Insert the Connection String under MS_TableConnectionString, check Update database and save.
How To Create An Azure Back-End For A Xamarin.Forms Application
  •  Now select the Web App created on Azure.
How To Create An Azure Back-End For A Xamarin.Forms Application
  •  We'll see something like in the following picture.
How To Create An Azure Back-End For A Xamarin.Forms Application
  •  Now, click on +Add in the Dependencies line, select Azure SQL Database and then click on next.
How To Create An Azure Back-End For A Xamarin.Forms Application
 
How To Create An Azure Back-End For A Xamarin.Forms Application
  •  Compile the fields with the correct data and then click on finish.
  •   We'll see something like the following.
How To Create An Azure Back-End For A Xamarin.Forms Application
  •  Click on Publish to deploy the SDK for .NET to Azure.
How To Create An Azure Back-End For A Xamarin.Forms Application
 
Step 3 - Deploy the Xamarin.Forms Application.
 
Now we'll work on the Xamarin.Forms application.
  • In Solution Explorer, expand the tree as shown in the following picture.
 How To Create An Azure Back-End For A Xamarin.Forms Application
  • Open the ZUMOAPPNAME.sln solution.
  • Open the Contents.cs file.
  • Replace the string after the @ with the WebApp URL we created on Azure.
How To Create An Azure Back-End For A Xamarin.Forms Application
 
How To Create An Azure Back-End For A Xamarin.Forms Application
 
How To Create An Azure Back-End For A Xamarin.Forms Application
  •  Verify the build configuration for Android and iOS.
How To Create An Azure Back-End For A Xamarin.Forms Application
 
How To Create An Azure Back-End For A Xamarin.Forms Application
  • Finally, launch the application (Ctrl + F5).
  • Add a task to the Android or iOS application, then pull to refresh both the emulators and we'll see the added task in both the lists. 
How To Create An Azure Back-End For A Xamarin.Forms Application
 
How To Create An Azure Back-End For A Xamarin.Forms Application
 
SUCCESS!!! We've created an Azure back-end for our own Xamarin.Forms application.
 

Conclusion

 
In this article, we've seen how to:
  • Deploy the SDK for .NET solutions on Azure.
  • Connect a basic ToDo application built with Xamarin.Forms to the Azure Back-End and the Azure SQL Database.
How you have seen, we used the ready-to-use solutions from the GitHub Repository by Microsoft without modifying it, just for simplicity. 
 
Of course, this is the base for your own future projects where you want to create an Azure back-end for your Xamarin.Forms application, and
you can modify the code to do it (please, read the LICENSE.txt file).
 
Don't forget to delete the Resource Group from Azure when your test is completed to avoid unwanted costs (the procedure to do it is at the end of Part One of this article). 
 
Sources
  • Microsoft Official Documentation,
    https://docs.microsoft.com/it-it/azure/app-service-mobile/app-service-mobile-xamarin-forms-get-started

  • Related GitHub Repository
    https://github.com/Azure/azure-mobile-apps-quickstarts
Thank you for your time and your attention.