20. 存取 Mobile Service
public partial class App : Application
{
internal static MobileServiceClient MobileService =
new MobileServiceClient("https://todo64.azure-mobile.net/",
"xisXQCpUGwQfwOwUqvxcqwkVhtdiLR72");
• 建立MobileServiceClient物件
21. 資料表與類別的對應
using Microsoft.WindowsAzure.MobileServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TodoApplication
{
[DataTable("todos")]
public class TodoDataModel
{
public int Id { get; set; }
public string Description { get; set; }
public bool Complete { get; set; }
}
}
• Windows Azure Mobile Services 會自動依據您定義的類別
來建立資料表結構
22. 添加處理使用者驗證的程式碼
public partial class MainPage : PhoneApplicationPage
{
private MobileServiceUser user;
private async System.Threading.Tasks.Task Authenticate()
{
while (user == null)
{
try
{
user = await App.MobileService.LoginAsync(MobileServiceAuthenticationProvider.Google);
}
catch (InvalidOperationException)
{
Dispatcher.BeginInvoke(() =>
{
MessageBox.Show("You must log in. Login Required");
});
}
}
}
private async void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
await Authenticate();
}
52. 參考資料
• Windows Azure Mobile Document
• http://www.windowsazure.com/en-
us/develop/mobile/reference/
• My Blog
• http://www.dotblogs.com.tw/code6421
• Windows Azure Mobile Service SDK for Windows
Phone 7
• https://github.com/zaxy78/azure-mobile-wp7-
sdk
• (unofficial)