2013-03-19 165 views
3

我正在开发Windows Phone 8的应用程序。我正在尝试使用这个非常简单的示例在这里执行身份验证:http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started-with-users-wp8/,后面跟着这个:http://www.windowsazure.com/en-us/develop/mobile/tutorials/authorize-users-in-scripts-wp8/。对于我的应用程序来说,继续能够对我的应用程序的用户进行身份验证和控制是非常重要的。具体来说,我的问题在这里:azure移动服务身份验证

private async System.Threading.Tasks.Task Authenticate() 
{ 
    while (user == null) 
    { 
     string message; 
     try 
     { 
      user = await App.MobileService 
         .LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount); 
      message = string.Format("You are now logged in - {0}", user.UserId); 
     } 
     catch (InvalidOperationException e) 
     { 
      message = e + "You must log in. Login Required"; 
     } 
     MessageBox.Show(message); 
    } 
} 

这是关于尽可能多的代码,这两个教程。它开始登录屏幕在user = await App.MobileService .LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount); 但接受登录凭据后,它开始显示错误消息是:

+  $exception {System.InvalidOperationException: Cannot start a login operation because login is already in progress. 

at Microsoft.WindowsAzure.MobileServices.MobileServiceClient.<SendLoginAsync>d__5.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
at System.Runtime.CompilerServices.TaskAwaiter1.GetResult() 
at SeeThrough.MainPage.<Authenticate>d__7.MoveNext()} System.Exception {System.InvalidOperationException} 

重复这个过程,因为“用户”从来没有被分配,由于“登录已进行中“的情况。我无法在网上找到任何帮助,我已经搜索了这个错误,只有4个点击的确切问题,这是github代码的一小部分,没有帮助,据我所知。

回答

0

我想你还没有正确配置帐户。请在实时仪表板的应用程序注册页面中提供正确的移动服务URL。如果URL不正确,则更有可能得到这种例外!

+0

在现场重定向URL连接开发呃中心与Azure Managment门户中显示的移动服务URL一致。客户端ID和客户端密码也都是ideticle。客户端ID是否必须在应用程序中它自己一些可能这是我的最终项目在uni它会让我失败,如果它没有排序很快 – user2120315 2013-03-22 20:23:40

+0

我试图改变ID提供者以及相同的结果 – user2120315 2013-03-24 16:31:33

0

老问题,但这帮了我。

引用答案从MSDN Forums

我忘了提,我们的教程还没有更新的窗口 电话8.1,那么你还需要添加以下代码以及 到您的App.xaml的.cs(该片段是一个万能的应用程序,手机8.1 将是相同的只是,而不需要它是有条件的)

protected override void OnActivated (IActivatedEventArgs args) 
{ 
    base.OnActivated (args); 

#if WINDOWS_PHONE_APP 
    if (args.Kind == ActivationKind.WebAuthenticationBrokerContinuation) 
     App.<mobileservice>.LoginComplete (args as WebAuthenticationBrokerContinuationEventArgs); 
#endif 
}