Azure移动服务身份验证 - App.MobileService不存在

时间:2012-11-18 06:08:07

标签: c# windows azure

我有一个Windows 8商店应用程序,我想为其添加Azure身份验证。我已经按照MSDN页面中的示例进行操作。但是,以下行给了我一些问题:

MobileServiceUser loginResult = await App.MobileService.LoginAsync(result.Session.AuthenticationToken);

错误是:App不包含MobileService的定义。什么时候将MobileService实例添加到App类?

我添加了对Microsoft.Live和Azure移动服务库的引用。这是整个Authenticate函数:

private async System.Threading.Tasks.Task Authenticate()
        {
        LiveAuthClient liveIdClient = new LiveAuthClient("<< INSERT REDIRECT DOMAIN HERE >>");


        while (session == null)
        {
            // Force a logout to make it easier to test with multiple Microsoft Accounts
            if (liveIdClient.CanLogout)
                liveIdClient.Logout();


            LiveLoginResult result = await liveIdClient.LoginAsync(new[] { "wl.basic" });
            if (result.Status == LiveConnectSessionStatus.Connected)
            {
                session = result.Session;
                LiveConnectClient client = new LiveConnectClient(result.Session);
                LiveOperationResult meResult = await client.GetAsync("me");
                MobileServiceUser loginResult = await App.MobileService.LoginAsync(result.Session.AuthenticationToken);

                string title = string.Format("Welcome {0}!", meResult.Result["first_name"]);
                var message = string.Format("You are now logged in - {0}", loginResult.UserId);
                var dialog = new MessageDialog(message, title);
                dialog.Commands.Add(new UICommand("OK"));
                await dialog.ShowAsync();
            }
            else
            {
                session = null;
                var dialog = new MessageDialog("You must log in.", "Login Required");
                dialog.Commands.Add(new UICommand("OK"));
                await dialog.ShowAsync();
            }
        }
    }

1 个答案:

答案 0 :(得分:9)

你必须自己添加课程。

在Azure移动服务“入门页面”上,选择“Windows应用商店”,然后选择“连接现有的WINDOWS商店应用”(并不意味着喊出来,它就像在页面上的所有大写字母一样!)

它会告诉您执行以下操作:

  

添加“using Microsoft.WindowsAzure.MobileServices;”,然后复制和   将以下代码粘贴到App.xaml.cs文件中:

public static MobileServiceClient MobileService = new MobileServiceClient(
    "https://[your website].azure-mobile.net/",
    "[your key]"
);