Azure Mobile Apps with .NET
Welcome to the Azure Mobile Apps tutorial for .NET developers. This guide walks you through building a mobile backend using Azure Mobile Apps SDK, setting up authentication, and connecting a Xamarin.Forms client.
Prerequisites
- Visual Studio 2022 (or newer) with ASP.NET and mobile development workloads.
- .NET 8 SDK
- Azure subscription (free tier works).
- Basic knowledge of C# and REST APIs.
1. Create the Azure Mobile App Backend
- Open Visual Studio → Create a new project.
- Select ASP.NET Core Web API and click Next.
- Configure the project:
- Name:
MyMobileBackend
- Location: choose a folder
- Framework:
.NET 8.0
- Name:
- Click Create.
After the project is generated, add the Azure Mobile Apps SDK via NuGet:
dotnet add package Microsoft.Azure.Mobile.Server
Now, modify Program.cs
to configure the Mobile App service:
using Microsoft.Azure.Mobile.Server;
using Microsoft.Azure.Mobile.Server.Config;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddMobileApp();
var app = builder.Build();
app.UseMobileApp(); // Enables mobile middleware
app.MapControllers();
app.Run();
2. Define a Data Model
Create a TodoItem.cs
model in the Models
folder:
using Microsoft.Azure.Mobile.Server;
using System.ComponentModel.DataAnnotations;
public class TodoItem : EntityData
{
[Required]
public string Text { get; set; }
public bool Complete { get; set; }
}
Then, add a controller for the model:
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Mobile.Server;
using Microsoft.Azure.Mobile.Server.Config;
[MobileAppTable]
[Route("tables/[controller]")]
public class TodoItemController : TableController<TodoItem>
{
private readonly MobileServiceContext _context = new MobileServiceContext();
public override IQueryable<TodoItem> GetAll()
{
return Query(); // Returns all items
}
public override async Task<SingleResult<TodoItem>> Lookup(string id)
{
return await LookupAsync(id);
}
public override async Task<TodoItem> InsertAsync(TodoItem item)
{
item = await InsertAsync(item);
return item;
}
public override async Task<TodoItem> UpdateAsync(string id, TodoItem item)
{
await UpdateAsync(id, item);
return item;
}
public override async Task DeleteAsync(string id)
{
await DeleteAsync(id);
}
}
Make sure to create MobileServiceContext
inheriting from DbContext
and configuring the TodoItems
DbSet.
3. Publish to Azure
- Right‑click the project → Publish.
- Select Azure → Azure App Service (Linux) → Create New.
- Fill out the App Service details (choose a unique name, region, pricing tier).
- Click Finish then Publish.
After deployment, the service will be available at https://<your-app-name>.azurewebsites.net
.
4. Connect a Xamarin.Forms Client
Add the Mobile Apps client SDK to the Xamarin project:
dotnet add package Microsoft.Azure.Mobile.Client
Initialize the client in your shared project:
using Microsoft.WindowsAzure.MobileServices;
public static class MobileService
{
public static MobileServiceClient Client { get; } =
new MobileServiceClient("https://<your-app-name>.azurewebsites.net");
}
Create a service to handle TodoItem
operations:
public class TodoService
{
private readonly IMobileServiceTable<TodoItem> _table;
public TodoService()
{
_table = MobileService.Client.GetTable<TodoItem>();
}
public async Task<IEnumerable<TodoItem>> GetItemsAsync()
{
return await _table.ToEnumerableAsync();
}
public async Task AddItemAsync(TodoItem item)
{
await _table.InsertAsync(item);
}
public async Task UpdateItemAsync(TodoItem item)
{
await _table.UpdateAsync(item);
}
public async Task DeleteItemAsync(TodoItem item)
{
await _table.DeleteAsync(item);
}
}
Bind the service to your UI using MVVM or code‑behind as preferred.
Next Steps
- Enable authentication (Azure Active Directory, Google, Facebook).
- Configure offline sync for mobile clients.
- Set up push notifications using Azure Notification Hubs.
- Monitor your service with Application Insights.