Building Mobile Apps with a Mobile Services .NET Backend
-
Upload
sasha-goldshtein -
Category
Technology
-
view
1.310 -
download
0
description
Transcript of Building Mobile Apps with a Mobile Services .NET Backend
![Page 1: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/1.jpg)
![Page 2: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/2.jpg)
Laat ons weten wat u vindt van deze sessie! Vul de evaluatie in via www.techdaysapp.nl en maak kans op een van de 20 prijzen*. Prijswinnaars worden bekend gemaakt via Twitter (#TechDaysNL). Gebruik hiervoor de code op uw badge.
Let us know how you feel about this session! Give your feedback via www.techdaysapp.nl and possibly win one of the 20 prizes*. Winners will be announced via Twitter (#TechDaysNL). Use your personal code on your badge.
* Over de uitslag kan niet worden gecorrespondeerd, prijzen zijn voorbeelden – All results are final, prizes are examples
![Page 3: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/3.jpg)
Building Mobile Apps with a Mobile Services .NET BackendSasha GoldshteinCTO, Sela GroupMicrosoft C# MVP, Azure MRS, Azure Insiderblog.sashag.net@goldshtn
![Page 4: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/4.jpg)
Who are we?App developers
What do we hate?Backends
![Page 5: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/5.jpg)
Azure Mobile Services is a backend for your mobile apps
… that has a free tier… and cloud scale… and support for all mobile platforms
![Page 6: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/6.jpg)
This talk will focus on the .NET backend and the C# clients
… the Node.js backend with iOS/Android clients was discussed earlier today
![Page 7: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/7.jpg)
Platforms and FeaturesPlatforms (client libraries)•Windows Phone•Windows 8• Xamarin• iOS• Android• HTML/JavaScript• PhoneGap
Features• Data and queries• Push notifications• Authentication• Data access customization• Custom API• Offline sync• Mass push• Remote debugging• Local deployment for testing
![Page 8: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/8.jpg)
System Diagram
Microsoft Azure
SQL Databas
e
ASP.NET Web API backend
Microsoft Push
Notification Service
Facebook Auth
Provider
Windows Notification
Service
Microsoft Auth Provider
![Page 9: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/9.jpg)
Data Queryvar service = new MobileServiceClient( “http://rentahome.azure-mobile.net/”, “<APPLICATION KEY>”);
var table = service.GetTable<Apartment>();
List<Apartment> apartments = await table.Where(a => a.Rented == false) .ToListAsync();
![Page 10: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/10.jpg)
Authenticationvar user = await service.LoginAsync( MobileAuthenticationProvider.Facebook);
![Page 11: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/11.jpg)
Client-Side Push Registrationvar channel = await PushNotificationChannelManager. CreatePushNotificationChannelForApplicationAsync();
await service.GetPush() .RegisterNativeAsync(channel.Uri);
![Page 12: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/12.jpg)
Visual Studio Support
![Page 13: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/13.jpg)
Server-Side Pushpublic async Task<IHTTPActionResult> PostApartment( Apartment apartment){ var inserted = await InsertAsync(apartment); var push = new ApplePushMessage( “Added apartment at ” + apartment.Address, null); await Services.Push.SendAsync(push); return CreatedAtRoute(“Tables”, new { id = inserted.Id }, inserted);}
![Page 14: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/14.jpg)
Server-Side Authorization[RequiresAuthorization(AuthorizationLevel.User)]public async Task<IHTTPActionResult> PostApartment( Apartment apartment){ var inserted = await InsertAsync(apartment); return CreatedAtRoute(“Tables”, new { id = inserted.Id }, inserted);}
![Page 15: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/15.jpg)
DemoBuilding the “Rent a Home”Windows Store Appwith the Mobile Services .NET Backend
![Page 16: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/16.jpg)
Offline Sync SupportCurrently in Preview, only for Windows Store appsUses SQLite backing storeManual push and pull, no auto-syncConflict detection and management
![Page 17: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/17.jpg)
Preparing Data Model for OfflineSync Supportpublic class Apartment{ public string Id { get; set; } public bool Rented { get; set; } public string Address { get; set; } public uint Bedrooms { get; set; } [Version] public string Version { get; set; }}
![Page 18: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/18.jpg)
Initializing Sync Table and Storevar table = service.GetSyncTable<Apartment>();if (!service.SyncContext.IsInitialized){ var store = new MobileServiceSQLiteStore(“my.db”); store.DefineTable<Apartment>() await service.SyncContext.InitializeAsync(store, new MobileServiceSyncHandler());}
![Page 19: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/19.jpg)
Pull and Push// May throw if there is a connection problemawait table.PullAsync();var list = await table.OrderBy(a => a.Bedrooms) .ToListAsync();
table.Insert(new Apartment(...));// May throw if there is a connection problem// or a conflict, cf. MobileServicePushFailedExceptionservice.SyncContext.PushAsync();
![Page 20: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/20.jpg)
DemoAdding Offline Sync Support
![Page 21: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/21.jpg)
Questions?Sasha Goldshteinblog.sashag.net@goldshtn
![Page 22: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/22.jpg)
Laat ons weten wat u vindt van deze sessie! Vul de evaluatie in via www.techdaysapp.nl en maak kans op een van de 20 prijzen*. Prijswinnaars worden bekend gemaakt via Twitter (#TechDaysNL). Gebruik hiervoor de code op uw badge.
Let us know how you feel about this session! Give your feedback via www.techdaysapp.nl and possibly win one of the 20 prizes*. Winners will be announced via Twitter (#TechDaysNL). Use your personal code on your badge.
* Over de uitslag kan niet worden gecorrespondeerd, prijzen zijn voorbeelden – All results are final, prizes are examples
![Page 23: Building Mobile Apps with a Mobile Services .NET Backend](https://reader036.fdocuments.us/reader036/viewer/2022062707/5585a716d8b42a711a8b4b87/html5/thumbnails/23.jpg)