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



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

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

错误为:应用程序不包含MobileService的定义。MobileService的实例何时添加到App类?

我添加了对Microsoft.Live和Azure移动服务库的引用。以下是整个身份验证功能:

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();
}
}
}

您必须自己添加类。

在Azure移动服务的"入门页面"上,选择"Windows应用商店",然后选择"连接现有的Windows应用商店应用程序"(不要大喊大叫,页面上的所有大写字母都是这样的!)。

它会告诉你做以下事情:

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

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

最新更新