📜 ⬆️ ⬇️

Mobile services for ASP.NET developers



Microsoft Azure mobile services provide developers with a turnkey solution for implementing a cloud backend in an application. Azure Mobile Services now fully supports the creation of server logic using the ASP.NET Web API and is a great choice for developers designing mobile APIs using ASP.NET:


Ready backend with a set of SDK for all mobile platforms


Getting started implementing mobile services in Visual Studio is easy. You need to go to the Microsoft Azure portal and create a new mobile service. On the first page, select .NET as the server side. After the service is created, go to the “Quickstart” tab and download the test project for the client platform on which you are developing.





In the event that you start working in Visual Studio , you can create a mobile service after developing a local project to publish it to the service.



In any case, you will receive a Mobile Services .NET project template. Please note that this is a regular Web API project that uses additional NuGet packages.



Open the controller file TodoItemController.cs and examine its contents. Set a breakpoint inside the GetAllTodoitems method. This controller will show you how to work with data using Mobile Services .NET support:

public class TodoItemController : TableController<TodoItem> { protected override void Initialize(HttpControllerContext controllerContext) { base.Initialize(controllerContext); csharp_testContext context = new csharp_testContext(); DomainManager = new EntityDomainManager<TodoItem>(context, Request, Services); } // GET tables/TodoItem public IQueryable<TodoItem> GetAllTodoItems() { return Query(); } // GET tables/TodoItem/48D68C86-6EA6-4C25-AA33-223FC9A27959 public SingleResult<TodoItem> GetTodoItem(string id) { return Lookup(id); } // PATCH tables/TodoItem/48D68C86-6EA6-4C25-AA33-223FC9A27959 public Task<TodoItem> PatchTodoItem(string id, Delta<TodoItem> patch) { return UpdateAsync(id, patch); } // POST tables/TodoItem/48D68C86-6EA6-4C25-AA33-223FC9A27959 public async Task<IHttpActionResult> PostTodoItem(TodoItem item) { TodoItem current = await InsertAsync(item); return CreatedAtRoute("Tables", new { id = current.Id }, current); } // DELETE tables/TodoItem/48D68C86-6EA6-4C25-AA33-223FC9A27959 public Task DeleteTodoItem(string id) { return DeleteAsync(id); } } 

Please note that all key TodoItem CRUD methods are already defined. By default, the EntityDomainManager controller wraps the Entity Framework model, which provides an easy transition to using alternative data storage:


With the support of .NET code in mobile services, running and debugging the logic of the mobile backend is available locally. We start the service with the F5 key, and on the service start page in the browser, click "Try it out".

.NET support in mobile services provides automatic generation of reference information for your Web API as a separate page. You can get a description of the method implementation using GET tables / TodoItem . Click on “Try this out” and then “Send” to call the GetAllTodoItems () method, and you get to the breakpoint that you set earlier.



After completing the development of the server-side API, you can publish your Web API to a mobile service. Publishing support is built into Visual Studio, just right-click on the project and select “Publish”. You can choose an existing mobile service or create a new one directly from Visual Studio without having to visit the Azure portal.



You can publish any existing WebAPI solution to a mobile service and immediately transfer its management and monitoring to Azure.

More information about the support of the .NET backend in mobile services can be found in the documentation:


First-class mobile API hosting


Let's talk a little about the benefits that the developer gets when publishing his API to the mobile service, because on the other hand there are many other ways to host the Web API in Azure.

We list only some of the advantages provided by mobile services:


Useful mobile backend features


Mobile services offer a large amount of functionality for your application right out of the box.
For example:


Connect to corporate systems


The choice of the .NET platform is one of the frequent corporate development scenarios, since the .NET family of languages ​​provides a large number of relevant scenarios for creating business applications :


Integration with Visual Studio


In addition to the already listed functionality, Visual Studio contains many other useful tools for developing and debugging your mobile service. For example, built-in scaffolding, which allows you to create table controllers (for storing relational data), user controllers (for building arbitrary APIs, HTTP), and scheduled tasks.



Visual Studio also provides remote debugging. Simply right-click on the mobile service in the "Solution Explorer" and select "Attach Debugger." In order to use this feature, make sure that you publish the code in “Debug” mode.



Another interesting feature in Solution Explorer is the “View Logs” command, which allows you to view logs filled in by your mobile service in the cloud, including error messages and stack traces.



We hope that you will appreciate the range of new features and capabilities of Azure Mobile Services, and encourage you to try them on your next project.

For recommendations or feedback, use Twitter: @theYavor .

useful links


Source: https://habr.com/ru/post/241680/


All Articles