2

我正在使用适用于 Android 的 Xamarin 并添加了 azure 移动服务组件。

我正在尝试创建待办事项列表应用程序,例如(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);

我使用adapter 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,当我在 t.Exception 中进行调试时,我发现Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException

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

已编辑 我可以获得异常级别的唯一方法是在调试时从监视窗口获取详细信息。异常有 2 个属性: Request&Response 请求: - 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 键“X-ZUMO-INSTALLATION-ID”
- [1] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair 键“X-ZUMO-APPLICATION”字符串值“FmlVNVhdQhNEAIZZVptKhxlQNuJrlq37”字符串+非公共成员
+原始视图
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" 字符串 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 + 静态成员
+ 非-public members
静态成员

响应 - 响应 {Microsoft.WindowsAzure.MobileServices.ServiceFilterResponse} Microsoft.WindowsAzure.MobileServices.ServiceFilterResponse 内容 "{\"code\":404,\"error\":\"Error: Not Found\"}" string 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 Key "Cache-Control" string Value "no-cache" string + Non-public members
- [1] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair Key “内容长度”字符串值“39”字符串+非公共成员
- [2] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair Key "Content-Type" string Value "application/json" string + 非公共成员
- [3] {System.Collections.Generic. KeyValuePair} System.Collections.Generic.KeyValuePair Key "Server" string Value "Microsoft-IIS/8.0" string + Non-public members
- [4] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair Key " Set-Cookie" string Value "ARRAffinity=3041b7170f63e41156a1ff0b65518583e91f68d4f90a680a7750bd8d12f209e0;Path=/;Domain=ichange.a..." string + 非公开成员
- [5] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair Key "x-zumo-version" string Value "Zumo.Main.0.1.6.3017.Runtime" string + 非公共成员
- [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
+ Raw View
ResponseStatus Microsoft.WindowsAzure.MobileServices.ServiceFilterResponseStatus.ProtocolError Microsoft.WindowsAzure.MobileServices.ServiceFilterResponseStatus StatusCode 404 int StatusDescription“未找到”字符串

4

1 回答 1

1

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

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

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

public static string mobileServiceUrl =
    "http://MyMoblieService.azure-mobile.net/";
于 2013-06-27T22:21:43.670 回答