Azure与Xamarin.Android;您必须登录才能使用此应用程序;

Azure与Xamarin.Android;您必须登录才能使用此应用程序;,xamarin.android,azure-mobile-services,Xamarin.android,Azure Mobile Services,我最近开始为我的最后一年项目学习移动开发,我正在使用Xamarin.Android和Azure移动服务开发一个Android应用程序。 我已经创建了一个测试数据库并在那里创建了一个条目,试图让我的Android应用程序连接到该数据库并检索该条目。我这样做是为了了解如何建立连接和检索数据,并从那里开始正确地修改。 这就是我的模型类的样子(请注意,JSON属性的命名与数据库中的列名称完全相同) using Newtonsoft.Json; namespace com.parkkl.intro.Mo

我最近开始为我的最后一年项目学习移动开发,我正在使用Xamarin.Android和Azure移动服务开发一个Android应用程序。 我已经创建了一个测试数据库并在那里创建了一个条目,试图让我的Android应用程序连接到该数据库并检索该条目。我这样做是为了了解如何建立连接和检索数据,并从那里开始正确地修改。 这就是我的模型类的样子(请注意,JSON属性的命名与数据库中的列名称完全相同)

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);
        }
    }
}
使用Android.App;
使用Microsoft.WindowsAzure.MobileServices;
使用Android.OS;
使用com.parkkl.intro.Models;
使用System.Collections.Generic;
使用Android.Widget;
名称空间com.parkkl.intro
{
[活动(Label=“ParkKL”,MainLauncher=false,Icon=“@drawable/Icon”)]
公共课活动:活动
{
#区域变量
公共静态MobileServiceClient=新的MobileServiceClient
(@"http://parkkl.azurewebsites.net/");
私有IMobileServiceTable测试=null;
私人名单测试;
#端区
创建时受保护的覆盖无效(捆绑包)
{
base.OnCreate(bundle);
//从“主”布局资源设置视图
SetContentView(Resource.Layout.Main);
test=client.GetTable();
testItems=新列表();
GetData();
}
公共异步void GetData()
{
var collection=wait test.Where(user=>user.Id==1.ToCollectionAsync();
foreach(集合中的var项)
{
测试项。添加(
新测试表
{
Id=项目Id,
用户名=item.UserName,
已删除=项目。已删除,
版本=项目。版本,
创建=项。创建,
更新=项目。已更新,
});
}
var finalItem=集合[0];
TextView text=(TextView)FindViewById(Resource.Id.TextFromDB);
text.Append(finalItem.UserName);
}
}
}
现在的问题是,每次我尝试部署应用程序时,它都会抛出这个异常

Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: 您必须登录才能使用此应用程序

在Azure中的应用程序服务中,我已禁用所有身份验证,但仍出现此错误。我想知道问题是从何而来的?!我将非常感谢您的帮助


编辑:我想我找到了问题所在,那就是表本身的权限问题。不过,我仍在寻找正确验证我的应用程序的方法。

有关如何处理身份验证的详细信息,请查看这本书。

有关如何处理身份验证的详细信息。

谢谢Adrian,我已经做了一点准备浏览这本书,它是非常全面和清晰的。它会对我帮助很大。除此之外,我还有一个问题。如何或什么是使用Azure web服务向我的应用程序注册新用户的最佳策略。这部分内容是在书中涵盖的还是需要更多研究?!我非常感谢分享这本书。这真的取决于你的情况推荐-没有“最佳”策略。因此,本书没有介绍它。谢谢你,阿德里安,实际上我刚刚在这里看到了你的博客()老实说,这真是难以置信的工作。我想我所需要的就是这些,所以非常感谢你的帮助阿德里安。谢谢阿德里安,我读了一点这本书,它非常全面和清晰。它将对我帮助很大。除此之外,我还有一个问题。如何或什么是向我的应用程序注册新用户的最佳策略,通过使用Azure web服务。这部分内容是否包含在本书中或需要更多研究?!我非常感谢分享这本书。这取决于你的情况-没有“最佳”策略。因此,本书没有涵盖这部分内容。谢谢Adrian,实际上我刚刚在这里看到你的博客()老实说,这真是难以置信的工作。我想我所需要的就是那里,所以非常感谢你的帮助阿德里安。