Xamarin MonoAndroid Azure移动服务InsertAsync

时间:2013-06-27 15:08:24

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

我在Android上使用Xamarin并添加了天蓝色的移动服务组件。

我试图创建像(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 Insert函数将数据插入表

   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时,我会在挖掘时挖掘出来。我发现Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException

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

被修改 我可以获得异常级别的唯一方法是在调试时从监视窗口获取详细信息。 该例外有2个属性:Request&amp; Response 请求: - 请求{Microsoft.WindowsAzure.MobileServices.ServiceFilterRequest} Microsoft.WindowsAzure.MobileServices.ServiceFilterRequest         接受&#34; application / json&#34;串         内容&#34; {\&#34; text \&#34;:\&#34; tyu \&#34;,\&#34;完成\&#34;:false}&#34;串         ContentType&#34; application / json&#34;串 - 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         键&#34; X-ZUMO-INSTALLATION-ID&#34;串         价值&#34; 17b22eec-edd2-4a15-a37f-d4c5d87e4e8e&#34;串 +非公开成员
- [1] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair         关键&#34; X-ZUMO-APPLICATION&#34;串         价值&#34; FmlVNVhdQhNEAIZZVptKhxlQNuJrlq37&#34;串 +非公开成员
+原始视图
        方法&#34; POST&#34;串 - Uri {System.Uri} System.Uri         AbsolutePath&#34; /.azure-mobile.net/tables/Item"串         绝对URI         权威&#34; ichange.azure-mobile.net&#34;串         DnsSafeHost&#34; ichange.azure-mobile.net&#34;串         片段&#34;&#34;串         主持人&#34; ichange.azure-mobile.net&#34;串         HostNameType System.UriHostNameType.Dns System.UriHostNameType         IsAbsoluteUri真正的布尔         IsDefaultPort真正的bool         IsFile假布尔         IsLoopback假布尔         IsUnc假布尔         LocalPath&#34; /.azure-mobile.net/tables/Item"串         OriginalString
        PathAndQuery&#34; /.azure-mobile.net/tables/Item"串         端口80 int         查询&#34;&#34;串         Scheme&#34; http&#34;串 + Segments {string [4]} string []         UserEscaped false bool         UserInfo&#34;&#34;串 +静态成员
+非公开成员
        静态成员

回应 - 响应{Microsoft.WindowsAzure.MobileServices.ServiceFilterResponse} Microsoft.WindowsAzure.MobileServices.ServiceFilterResponse         内容&#34; {\&#34;代码\&#34;:404,\&#34;错误\&#34;:\&#34;错误:未找到\&#34;}&#34 ;串         ContentType&#34; application / json&#34;串 - 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         密钥&#34;缓存控制&#34;串         价值&#34; no-cache&#34;串 +非公开成员
- [1] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair         关键&#34;内容长度&#34;串         价值&#34; 39&#34;串 +非公开成员
- [2] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair         键&#34;内容类型&#34;串         价值&#34; application / json&#34;串 +非公开成员
- [3] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair         关键&#34;服务器&#34;串         价值&#34; Microsoft-IIS / 8.0&#34;串 +非公开成员
- [4] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair         Key&#34; Set-Cookie&#34;串         值&#34; ARRAffinity = 3041b7170f63e41156a1ff0b65518583e91f68d4f90a680a7750bd8d12f209e0; Path = /; Domain = ichange.a ...&#34;串 +非公开成员
- [5] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair         Key&#34; x-zumo-version&#34;串         价值&#34; Zumo.Main.0.1.6.3017.Runtime&#34;串 +非公开成员
- [6] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair         Key&#34; X-Powered-By&#34;串         价值&#34; ASP.NET&#34;串 +非公开成员
- [7] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair         关键&#34;日期&#34;串         价值&#34;星期四,2013年6月27日18:23:56 GMT&#34;串 +非公开成员
+原始视图
        ResponseStatus Microsoft.WindowsAzure.MobileServices.ServiceFilterResponseStatus.ProtocolError Microsoft.WindowsAzure.MobileServices.ServiceFilterResponseStatus         StatusCode 404 int         StatusDescription&#34; Not Found&#34;串

1 个答案:

答案 0 :(得分:1)

正如我们在评论中所讨论的那样:您传递给MobileServiceClient构造函数的URL不正确。 “未找到”回复让我查看您拥有的网址:

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

这是不正确的。它应该如下所示:

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