C# Azure移动服务身份验证-App.MobileService不存在
我有一个Windows 8应用商店应用程序,我想向其中添加Azure身份验证。我遵循了MSDN页面中的示例。但是,下面这一行给了我一些问题:C# Azure移动服务身份验证-App.MobileService不存在,c#,windows,azure,C#,Windows,Azure,我有一个Windows 8应用商店应用程序,我想向其中添加Azure身份验证。我遵循了MSDN页面中的示例。但是,下面这一行给了我一些问题: MobileServiceUser loginResult = await App.MobileService.LoginAsync(result.Session.AuthenticationToken); 错误是:应用程序不包含MobileService的定义。MobileService的实例何时添加到App类 我已经添加了对Microsoft.Liv
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();
}
}
}
private async System.Threading.Tasks.Task Authenticate()
{
LiveAuthClient liveIdClient=新的LiveAuthClient(“>”);
while(会话==null)
{
//强制注销以使多个Microsoft帐户的测试更容易
if(liveIdClient.CanLogout)
liveIdClient.Logout();
LiveLoginResult结果=等待liveIdClient.LoginAsync(新[]{“wl.basic”});
if(result.Status==LiveConnectSessionStatus.Connected)
{
会话=结果。会话;
LiveConnectClient=新的LiveConnectClient(result.Session);
LiveOperationResult-meResult=await client.GetAsync(“me”);
MobileServiceUser loginResult=wait App.MobileService.LoginAsync(result.Session.AuthenticationToken);
string title=string.Format(“Welcome{0}!”,meResult.Result[“first_name”]);
var message=string.Format(“您现在登录到-{0}”,loginResult.UserId);
var dialog=新建消息对话框(消息、标题);
添加(新的UICommand(“OK”);
wait dialog.ShowAsync();
}
其他的
{
会话=空;
var dialog=newmessagedialog(“您必须登录”,“需要登录”);
添加(新的UICommand(“OK”);
wait 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]"
);
另一个论坛上一位名叫Chris的人给出了这样的答案:转到您的管理仪表板,选择您的移动应用程序,然后单击“开始”下的“连接现有Windows应用商店应用程序”链接。然后将给定的代码复制到应用程序类。这就是我错过的。