简体   繁体   English

Xamarin MonoAndroid Azure移动服务InsertAsync

[英]Xamarin MonoAndroid Azure mobile service InsertAsync

I'm using Xamarin for Android and have added the azure mobile services componenet. 我正在使用Xamarin for Android,并添加了天蓝色的移动服务componenet。

I'm trying to create the todo list application like ( https://github.com/xamarin/azure-mobile-services ) 我正在尝试创建待办事项列表应用程序,例如( https://github.com/xamarin/azure-mobile-services

I connect to the mobile service like this: 我这样连接到移动服务:

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);

I use the adapte Insert function to insert data into the table 我使用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);
}

and everytime I get t.IsFaulted = true , while debuging when I dig in t.Exception I find Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException 每当我在挖掘t.Exception时进行调试时,每次获取t.IsFaulted = true时,我都会发现Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException

I would be glad to supply the rest of the code if needed. 如果需要,我很乐意提供其余代码。

Edited The only way I could get the exception level is by getting the details from the watch window while debugging. 编辑获得异常级别的唯一方法是在调试时从监视窗口获取详细信息。 The exception has 2 attributes: Request&Response The request: - Request {Microsoft.WindowsAzure.MobileServices.ServiceFilterRequest} Microsoft.WindowsAzure.MobileServices.ServiceFilterRequest Accept "application/json" string Content "{\\"text\\": \\"tyu\\", \\"complete\\": false}" string ContentType "application/json" string - Headers Count=2 System.Collections.Generic.Dictionary - Items {System.Collections.Generic.KeyValuePair[2]} System.Collections.Generic.KeyValuePair[] - [0] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair Key "X-ZUMO-INSTALLATION-ID" string Value "17b22eec-edd2-4a15-a37f-d4c5d87e4e8e" string + Non-public members 异常具有2个属性:Request&Response请求:-请求{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 Key "X-ZUMO-APPLICATION" string Value "FmlVNVhdQhNEAIZZVptKhxlQNuJrlq37" string + Non-public members -[1] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair密钥“ X-ZUMO-APPLICATION”字符串值“ FmlVNVhdQhNEAIZZVptKhxlQNuJrlq37”字符串+非公共成员
+ Raw View +原始视图
Method "POST" string - Uri {System.Uri} System.Uri AbsolutePath "/.azure-mobile.net/tables/Item" string AbsoluteUri Authority "ichange.azure-mobile.net" string DnsSafeHost "ichange.azure-mobile.net" string Fragment "" string Host "ichange.azure-mobile.net" string HostNameType System.UriHostNameType.Dns System.UriHostNameType IsAbsoluteUri true bool IsDefaultPort true bool IsFile false bool IsLoopback false bool IsUnc false bool LocalPath "/.azure-mobile.net/tables/Item" string OriginalString 方法“ POST”字符串-Uri {System.Uri} System.Uri AbsolutePath“ /.azure-mobile.net/tables/Item”字符串AbsoluteUri授权“ ichange.azure-mobile.net”字符串DnsSafeHost“ ichange.azure-mobile。 net“字符串片段”“字符串主机” ichange.azure-mobile.net“字符串HostNameType System.UriHostNameType.Dns System.UriHostNameType IsAbsoluteUri true bool IsDefaultPort true bool IsFile false bool IsLoopback false bool IsUnc false bool LocalPath” /.azure-mobile。 net / tables / Item“字符串OriginalString
PathAndQuery "/.azure-mobile.net/tables/Item" string Port 80 int Query "" string Scheme "http" string + Segments {string[4]} string[] UserEscaped false bool UserInfo "" string + Static members PathAndQuery“ /.azure-mobile.net/tables/Item”字符串Port 80 int Query“”字符串Scheme“ http”字符串+段{string [4]} string [] UserEscaped false bool UserInfo“”字符串+静态成员
+ Non-public members +非公开成员
Static members 静态成员

The response - Response {Microsoft.WindowsAzure.MobileServices.ServiceFilterResponse} Microsoft.WindowsAzure.MobileServices.ServiceFilterResponse Content "{\\"code\\":404,\\"error\\":\\"Error: Not Found\\"}" string ContentType "application/json" string - Headers Count=8 System.Collections.Generic.Dictionary - Items {System.Collections.Generic.KeyValuePair[8]} System.Collections.Generic.KeyValuePair[] - [0] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair Key "Cache-Control" string Value "no-cache" string + Non-public members 响应-响应{Microsoft.WindowsAzure.MobileServices.ServiceFilterResponse} Microsoft.WindowsAzure.MobileServices.ServiceFilterResponse内容“ {\\” code \\“:404,\\” error \\“:\\” Error:Not Found \\“}”字符串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密钥“缓存控件”字符串值“无缓存”字符串+非公共成员
- [1] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair Key "Content-Length" string Value "39" string + Non-public members -[1] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair关键字“ Content-Length”字符串值“ 39”字符串+非公共成员
- [2] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair Key "Content-Type" string Value "application/json" string + Non-public members -[2] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair关键字“ Content-Type”字符串值“ application / json”字符串+非公共成员
- [3] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair Key "Server" string Value "Microsoft-IIS/8.0" string + Non-public members -[3] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair密钥“服务器”字符串值“ Microsoft-IIS / 8.0”字符串+非公共成员
- [4] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair Key "Set-Cookie" string Value "ARRAffinity=3041b7170f63e41156a1ff0b65518583e91f68d4f90a680a7750bd8d12f209e0;Path=/;Domain=ichange.a…" string + Non-public members -[4] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair关键字“ Set-Cookie”字符串值“ ARRAffinity = 3041b7170f63e41156a1ff0b65518583e91f68d4f90a680a7750bd8d12f209e0; Path = /; Domain = ichange”。
- [5] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair Key "x-zumo-version" string Value "Zumo.Main.0.1.6.3017.Runtime" string + Non-public members -[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 Key "X-Powered-By" string Value "ASP.NET" string + Non-public members -[6] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair密钥“ X-Powered-By”字符串值“ ASP.NET”字符串+非公共成员
- [7] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair Key "Date" string Value "Thu, 27 Jun 2013 18:23:56 GMT" string + Non-public members -[7] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair关键字“日期”字符串值“ 2013年6月27日星期四18:23:56 GMT”字符串+非公开成员
+ Raw View +原始视图
ResponseStatus Microsoft.WindowsAzure.MobileServices.ServiceFilterResponseStatus.ProtocolError Microsoft.WindowsAzure.MobileServices.ServiceFilterResponseStatus StatusCode 404 int StatusDescription "Not Found" string ResponseStatus Microsoft.WindowsAzure.MobileServices.ServiceFilterResponseStatus.ProtocolError Microsoft.WindowsAzure.MobileServices.ServiceFilterResponseStatus StatusCode 404 int StatusDescription“未找到”字符串

As we discussed in the comments: the URL you're passing to the MobileServiceClient constructor is incorrect. 正如我们在评论中讨论的那样:您传递给MobileServiceClient构造函数的URL不正确。 The 'Not Found' response made me look in the URL which you have: “未找到”响应使我查找了您拥有的URL:

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

And that's incorrect. 那是不对的。 It should be as shown below: 它应该如下图所示:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM