2012-11-18 16 views
5

私はWindows 8 Storeアプリケーションを持っています。私はそれにAzure認証を追加したいと思います。私はMSDNページの例に従っています。ただし、次の行で問題が発生しています。Azureモバイルサービス認証 - App.MobileServiceが存在しません

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

エラー:アプリケーションにMobileServiceの定義が含まれていません。 MobileServiceのインスタンスはいつAppクラスに追加されますか?

Microsoft.LiveとAzure Mobile Servicesライブラリへの参照が追加されました。

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

別のフォーラムでChrisという名前のユーザーがこの回答を出しました。管理ダッシュボードに移動して、モバイルアプリを選択し、[GET STARTED]の[既存のWindowsストアアプリを接続]リンクをクリックします。次に、与えられたコードをAppクラスにコピーします。それは私が欠けていたものです。 – user1490586

答えて

9

あなた自身でクラスを追加する必要があります。

Azure Mobile Servicesの「はじめのページ」で「Windows Store」を選択し、「既存のWindowsストアを接続」を選択します(叫ぶことを意味するわけではありません。 )。コピーし、そして あなたのApp.xaml.csファイルに次のコードを貼り付け、「使用してMicrosoft.WindowsAzure.MobileServices」

追加:

これは、次の操作を行うことを教えてくれます

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

+1は「叫ぶつもりはありませんでした」。 – akshay2000

関連する問題