我的xamarin应用程序上的注册和登录功能突然停止工作。它有时会给出:
未处理的异常:Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException:发生
和其他时间:
未处理的异常:Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException:无法完成请求。 (内部服务器错误)发生
我没有改变这些页面上的任何内容来影响它们。唯一发生的事情是我的azure订阅已经过时了,我续订了它。除非我缺少一些设置,否则连接仍然是相同的。
我确定两个页面上的问题都是一样的,所以我只是在这里显示我的注册页面。如果您需要查看我的登录信息,请告诉我。
编辑1:我添加了一个try / catch,它总是进入catch。
编辑2:应用程序可能在其主线程上做了太多工作。
出现在日志中,不知道为什么它突然一直给出这些例外情况,我尝试的任何内容都没有显示任何改进。
编辑3:尝试干净的构建,unistall,重新安装,但现在我不知所措。它一直工作到今天,现在我得到上面提到的这些问题,我似乎没有做任何事情似乎解决它。
EditText Username = FindViewById<EditText>(Resource.Id.txtUsername);
EditText Password = FindViewById<EditText>(Resource.Id.txtPassword);
EditText ConfirmPassword = FindViewById<EditText>(Resource.Id.txtConfirmPassword);
if (Password.Text == ConfirmPassword.Text)
{
try
{
string hashedPassword = PasswordStorage.CreateHash(Password.Text);
string userName = Username.Text.Trim();
users newU = new users { username = userName, password = hashedPassword };
List<users> allUsers = await Client.GetTable<users>().ToListAsync();
Toast.MakeText(this, "Awaits table", ToastLength.Short).Show();
users u = allUsers.FirstOrDefault(x => x.username == newU.username);
if (u == null)
{
DBHelper.InsertNewUser(newU);
Toast.MakeText(this, "User " + newU.username + " created! You can now log in!", ToastLength.Short).Show();
StartActivity(typeof(MainActivity));
}
else
{
Toast.MakeText(this, "User " + u.username + " already exists!", ToastLength.Short).Show();
}
}
catch (Exception)
{
Toast.MakeText(this, "Time out", ToastLength.Short).Show();
}
}
答案 0 :(得分:0)
对于您的代码,您可以针对在线表格优化查询,如下所示:
var client = new MobileServiceClient("https://<your-app-name>.azurewebsites.net");
var users = await client.GetTable<users>().Where(u=>u.username == newU.username).ToListAsync();
if(users.Any())
{
//user exists
}
else
{
//add new user
}
对于您的方案,我建议您Enable diagnostics logging捕获详细错误。对于C#后端,您可以在config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;
文件下指定Startup.MobileApp.cs
,然后您可以检索响应中的详细错误。您需要调试代码并使用fiddler捕获网络跟踪,Client.GetTable<users>().ToListAsync()
或DBHelper.InsertNewUser(newU)
可能会引发错误,因此您需要自行进行故障排除。如果您无法解决此问题,可以使用您尝试的更详细步骤更新问题,并为我们检索详细的请求跟踪以缩小此问题。
此外,你可以关注adrian hall的关于The Mobile Client的书。