【问题标题】:Azure Mobile Service Authentication - App.MobileService does not existAzure 移动服务身份验证 - App.MobileService 不存在
【发布时间】:2013-09-24 14:50:50
【问题描述】:

我有一个 Windows 8 应用商店应用程序,我想向它添加 Azure 身份验证。我遵循了 MSDN 页面中的示例。但是,以下行给了我问题:

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

错误是:应用程序不包含 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();
            }
        }
    }

【问题讨论】:

  • 另一个论坛上名叫 Chris 的人给出了这样的答案:转到您的管理仪表板,选择您的移动应用程序,然后单击开始下的“连接现有的 Windows 应用商店应用程序”链接。然后将给定的代码复制到您的 App 类。这就是我所缺少的。

标签: c# windows azure


【解决方案1】:

你必须自己添加类。

在 Azure 移动服务“入门页面”上,选择“Windows 应用商店”,然后选择“连接现有的 WINDOWS 商店应用程序”(不要大喊大叫,页面上的字面意思就是这样!) .

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

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-12
    • 1970-01-01
    相关资源
    最近更新 更多