我最近开始为我的Final Year Project学习移动开发,并使用Xamarin.Android和Azure移动服务开发Android应用程序。 我创建了一个测试数据库并在那里创建了一个条目,试图使我的Android应用程序连接到数据库并检索此条目。我正在这样做以了解如何建立连接和检索数据,并从那里开始正确修改。 这是我的模型类什么样子(注意,JSON属性被命名完全一样在我的数据库中的列名。Azure with Xamarin.Android“您必须先登录才能使用此应用程序”
using Newtonsoft.Json;
namespace com.parkkl.intro.Models
{
class TestTable
{
public int Id { get; set; }
[JsonProperty(PropertyName = "UserName")]
public string UserName { get; set; }
[JsonProperty(PropertyName = "deleted")]
public bool Deleted { get; set; }
[JsonProperty(PropertyName = "version")]
public string Version { get; set; }
[JsonProperty(PropertyName = "createdAt")]
public string Creation { get; set; }
[JsonProperty(PropertyName = "updatedAt")]
public string Updated { get; set; }
}
}
这就是我的活动看起来怎么样
using Android.App;
using Microsoft.WindowsAzure.MobileServices;
using Android.OS;
using com.parkkl.intro.Models;
using System.Collections.Generic;
using Android.Widget;
namespace com.parkkl.intro
{
[Activity(Label = "ParkKL", MainLauncher = false, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
#region Variables
public static MobileServiceClient client = new MobileServiceClient
(@"http://parkkl.azurewebsites.net/");
private IMobileServiceTable<TestTable> test = null;
private List<TestTable> testItems;
#endregion
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
test = client.GetTable<TestTable>();
testItems = new List<TestTable>();
GetData();
}
public async void GetData()
{
var collection = await test.Where(user => user.Id == 1).ToCollectionAsync();
foreach (var item in collection)
{
testItems.Add(
new TestTable
{
Id = item.Id,
UserName = item.UserName,
Deleted = item.Deleted,
Version = item.Version,
Creation = item.Creation,
Updated = item.Updated,
});
}
var finalItem = collection[0];
TextView text = (TextView)FindViewById(Resource.Id.TextFromDB);
text.Append(finalItem.UserName);
}
}
}
现在的问题是,我每次尝试部署的应用程序时,它抛出该异常
Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: 你必须先登录在使用此应用程序
在我在Azure中的应用程序服务中,我已禁用所有身份验证,仍然出现此错误。我想知道问题来自哪里?!我会非常感谢你的帮助。
编辑:我想我发现了问题,这是表本身给出的权限。但是,我仍然找到一种方法来正确验证我的应用程序
谢谢阿德里安,我对这本书有所了解,它非常全面和清晰。它会帮助我很多。 我只是有一个问题,除此之外。通过使用Azure Web服务,将新用户注册到我的应用的最佳策略是什么或什么是最佳策略。这部分是在书中还是需要更多的研究?! 我真的很感谢分享这本书。 –
这真的取决于你的情况 - 没有“最好”的策略。因此,本书未涵盖在内。 –
谢谢阿德里安,其实我刚刚在这里遇到了你的博客(https://shellmonger.com/30-days-of-azure-mobile-apps-the-table-of-contents/),说实话,真是令人难以置信的工作。我想我需要的只是在那里,所以非常感谢你的帮助Adrian。 –