【发布时间】: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 类。这就是我所缺少的。