c# - Xamarin MonoAndroid Azure移动服务InsertAsync

标签 c# azure xamarin.android xamarin azure-mobile-services

我正在使用Xamarin for Android,并添加了天蓝色的移动服务componenet。

我正在尝试创建(https://github.com/xamarin/azure-mobile-services)之类的待办事项列表应用程序

我这样连接到移动服务:

public static string mobileServiceUrl = "http://MyMoblieService.azure-mobile.net/.azure-mobile.net/";
public static string mobileServiceAppKey = "MyAppKey";

private static readonly MobileServiceClient MobileService =
            new MobileServiceClient(mobileServiceUrl, mobileServiceAppKey);

this.adapter = new TodoAdapter(MobileService.GetTable<Item>(), this);


我使用Adapte插入功能将数据插入表中

   public void Insert(Item item)
   {
    IsUpdating = true;
    this.items.Add(item);
    NotifyDataSetChanged();

    this.table.InsertAsync(item).ContinueWith(t =>
    {
        if (t.IsFaulted)
        {
            this.items.Remove(item);
            NotifyDataSetChanged();
        }

        IsUpdating = false;
    }, scheduler);
}


并且每次我得到t.IsFaulted = true时,我在挖掘t.Exception时进行调试时都会发现Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException

如果需要,我很乐意提供其余代码。

已编辑
我可以获得异常级别的唯一方法是在调试时从监视窗口获取详细信息。
异常具有2个属性:请求与响应
要求:
-请求{Microsoft.WindowsAzure.MobileServices.ServiceFilterRequest} Microsoft.WindowsAzure.MobileServices.ServiceFilterRequest
        接受“ application / json”字符串
        内容“ {\” text \“:\” tyu \“,\” complete \“:false}”字符串
        ContentType“ application / json”字符串
-标头计数= 2 System.Collections.Generic.Dictionary
-项目{System.Collections.Generic.KeyValuePair [2]} System.Collections.Generic.KeyValuePair []
-[0] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair
        键“ X-ZUMO-INSTALLATION-ID”字符串
        值“ 17b22eec-edd2-4a15-a37f-d4c5d87e4e8e”字符串
+非公开成员
-[1] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair
        键“ X-ZUMO-APPLICATION”字符串
        值“ FmlVNVhdQhNEAIZZVptKhxlQNuJrlq37”字符串
+非公开成员
+原始视图
        方法“ POST”字符串
-Uri {System.Uri} System.Uri
        AbsolutePath“ /.azure-mobile.net/tables/Item”字符串
        绝对乌里
        授权“ ichange.azure-mobile.net”字符串
        DnsSafeHost“ ichange.azure-mobile.net”字符串
        片段“”字符串
        主机“ ichange.azure-mobile.net”字符串
        HostNameType System.UriHostNameType.Dns System.UriHostNameType
        IsAbsoluteUri真布尔
        IsDefaultPort true布尔
        IsFile错误布尔
        IsLoopback错误布尔
        IsUnc假布尔
        LocalPath“ /.azure-mobile.net/tables/Item”字符串
        原始字符串
        PathAndQuery“ /.azure-mobile.net/tables/Item”字符串
        80号港口int
        请求参数
        方案“ http”字符串
+段{string [4]}字符串[]
        用户转义的错误布尔
        UserInfo“”字符串
+静态成员
+非公开成员
        静态成员

响应
-响应{Microsoft.WindowsAzure.MobileServices.ServiceFilterResponse} Microsoft.WindowsAzure.MobileServices.ServiceFilterResponse
        内容“ {\” code \“:404,\” error \“:\”错误:未找到\“}”字符串
        ContentType“ application / json”字符串
-标头计数= 8 System.Collections.Generic.Dictionary
-项目{System.Collections.Generic.KeyValuePair [8]} System.Collections.Generic.KeyValuePair []
-[0] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair
        键“缓存控制”字符串
        值“ no-cache”字符串
+非公开成员
-[1] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair
        键“ Content-Length”字符串
        值“ 39”的字符串
+非公开成员
-[2] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair
        键“ Content-Type”字符串
        值“ application / json”字符串
+非公开成员
-[3] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair
        键“服务器”字符串
        值“ Microsoft-IIS / 8.0”字符串
+非公开成员
-[4] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair
        键“ Set-Cookie”字符串
        值“ ARRAffinity = 3041b7170f63e41156a1ff0b65518583e91f68d4f90a680a7750bd8d12f209e0; Path = /; Domain = ichange.a…”字符串
+非公开成员
-[5] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair
        键“ x-zumo-version”字符串
        值“ Zumo.Main.0.1.6.3017.Runtime”字符串
+非公开成员
-[6] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair
        键“ X-Powered-By”字符串
        值“ ASP.NET”字符串
+非公开成员
-[7] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair
        键“日期”字符串
        值“ 2013年6月27日星期四18:23:56 GMT”字符串
+非公开成员
+原始视图
        ResponseStatus Microsoft.WindowsAzure.MobileServices.ServiceFilterResponseStatus.ProtocolError Microsoft.WindowsAzure.MobileServices.ServiceFilterResponseStatus
        StatusCode 404整数
        StatusDescription“未找到”字符串

最佳答案

正如我们在评论中讨论的那样:您传递给MobileServiceClient构造函数的URL不正确。 “未找到”响应使我查找了您拥有的URL:

public static string mobileServiceUrl =
    "http://MyMoblieService.azure-mobile.net/.azure-mobile.net/";


那是不对的。它应该如下图所示:

public static string mobileServiceUrl =
    "http://MyMoblieService.azure-mobile.net/";

关于c# - Xamarin MonoAndroid Azure移动服务InsertAsync,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17346847/

相关文章:

c# - Unity 3d错误CS0246 : The type or namespace name 'ParticleEmitter' could not be found

sql-server - 无法使用sequelize 连接到SQL Azure 数据库,但本地主机上的SQL Server 工作正常

c# - 在安装 NuGet 时将文件复制到 Android 项目

azure - 无法加载 Microsoft.WindowsAzure.ServiceRuntime,版本=1.8.0.0,........................本地工作正常

.net - .NET 4.5 和 Authorize.net 升级到 TLS 1.2 的过程

c# - 无法连接到 Android 上的 TCP 端口

c# - 如何在单击按钮时发送远程通知? Xamarin.Android C#

C# 方法返回连接到不同数据库

c# - wordpress 最好的 C# 代码高亮插件是什么?

C# 声明同一个表的多个实例