5

I have a Windows 8 Store Application and I want to add Azure Authentication to it. I have followed the example in the MSDN page. However, the following line is giving me issues:

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

The error is: App does not contain a definition for MobileService. When does an instance of MobileService get added to the App class?

I have added references to the Microsoft.Live and Azure Mobile Services libraries. Here is the entire Authenticate function:

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
  • 1
    Someone named Chris on another forum gave this answer: Go to your management dashboard, select your mobile app and click the "Connect an existing Windows Store App" link under GET STARTED. Then copy the code given their to your App class. Which is what I was missing. Commented Nov 18, 2012 at 10:15

1 Answer 1

9

You have to add the class yourself.

On the Azure Mobile Services "Getting Started Page", select "Windows Store", and then "CONNECT AN EXISTING WINDOWS STORE APP" (don't mean to shout, it's literally in all caps on the page like that!).

It will tell you to do the following:

Add "using Microsoft.WindowsAzure.MobileServices;", then copy and paste the following code into your App.xaml.cs file:

public static MobileServiceClient MobileService = new MobileServiceClient( "https://[your website].azure-mobile.net/", "[your key]" ); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.