我已经在服务器和应用程序的Windows应用商店版本中设置并正常工作,但是我可以使用相同的问题,因此我严格按照this article中列出的步骤创建了一个测试应用程序 . 示例应用程序在UI上有一个按钮,按下时将尝试使用Twitter对用户进行身份验证 .
我从UI看到的流程是:
-
按按钮
-
屏幕变黑了一会儿
-
屏幕显示带有微调器的"Resuming..."
-
会捕获InvalidOperationException
例外细节:
已捕获System.InvalidOperationException HResult = -2146233079消息=用户已取消身份验证 . Source = mscorlib StackTrace:
在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)
在System.Runtime.CompilerServices.TaskAwaiter1.GetResult() 在Microsoft.WindowsAzure.MobileServices.MobileServiceAuthentication . <LoginAsync> d__0.MoveNext() ---从抛出异常的先前位置开始的堆栈跟踪结束--- 在System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(任务任务) 在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务) 在System.Runtime.CompilerServices.TaskAwaiter
1.GetResult()
在MobileAuthTest.MainPage . <AuthenticateAsync> d _3.MoveNext()
的InnerException:
我正在使用的代码几乎是从文章中逐字复制的,但我也会在这里粘贴它:
private async void Button_Click(object sender, RoutedEventArgs e)
{
await this.AuthenticateAsync();
}
// Define a method that performs the authentication process
// using a Twitter sign-in.
private async Task AuthenticateAsync()
{
while (user == null)
{
string message;
try
{
// Change 'MobileService' to the name of your MobileServiceClient instance.
// Sign-in using Twitter authentication.
user = await App.mobileService
.LoginAsync(MobileServiceAuthenticationProvider.Twitter);
message =
string.Format("You are now signed in - {0}", user.UserId);
}
catch (InvalidOperationException)
{
message = "You must log in. Login Required";
}
var dialog = new MessageDialog(message);
dialog.Commands.Add(new UICommand("OK"));
await dialog.ShowAsync();
}
}
这个覆盖在App.xaml.cs中:
protected override void OnActivated(IActivatedEventArgs args)
{
// Windows Phone 8.1 requires you to handle the respose from the WebAuthenticationBroker.
#if WINDOWS_PHONE_APP
if (args.Kind == ActivationKind.WebAuthenticationBrokerContinuation)
{
// Completes the sign-in process started by LoginAsync.
// Change 'MobileService' to the name of your MobileServiceClient instance.
mobileService.LoginComplete(args as WebAuthenticationBrokerContinuationEventArgs);
}
#endif
base.OnActivated(args);
}
我的测试全部都在真正的Windows Phone 8.1设备上(诺基亚920和8.1更新) .
值得指出的是,我目前正在尝试使用它的项目也在使用适用于Android,iOS和Windows Phone的Xamarin.Forms(我希望对Windows Phone的Xamarin.Forms和Windows Phone的通用应用程序进行比较) . 除了两个Windows Phone应用程序外,所有应用程序都可以正常运行 . Xamarin.Forms Windows Phone应用程序是一个Windows Phone Silverlight 8.1应用程序,其作用与上面针对Universal WP所述的相同,但失败并显示错误“验证失败,HTTP响应代码为0” .
我一直在四处寻找并且没有发现任何其他人遇到同样问题的案例 . 有什么我需要做的就是这么简单没有人觉得有必要用书面说出来吗?
1 回答
好吧,事实证明,我看到的问题可能只是我的设备 . 我将示例应用程序发送给另一个开发人员进行测试,他没有任何问题 . 我还能够在模拟器上使用示例应用程序和真实应用程序成功登录 . 这不完全是一个彻底的测试样本,但它足以让我停止在这张 table 上敲我的头 .