5

我有一个 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();
            }
        }
    }
4

1 回答 1

9

You have to add the class yourself.

On the Azure Mobile Services "Getting Started Page", select "Windows Store", and then "CONNECT AN EXISTING WINDOWS STORE APP" (don't mean to shout, it's literally in all caps on the page like that!).

It will tell you to do the following:

Add "using Microsoft.WindowsAzure.MobileServices;", then copy and paste the following code into your App.xaml.cs file:

public static MobileServiceClient MobileService = new MobileServiceClient(
    "https://[your website].azure-mobile.net/",
    "[your key]"
);
于 2013-06-17T04:31:18.277 回答