2013-06-27 77 views
1

我在Android上使用Xamarin並添加了azure移動服務組件。Xamarin MonoAndroid Azure移動服務InsertAsync

我想創建(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 接受 「應用/ JSON」 串 內容 「{\」 文本\」 :\「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」 串 +非公共成員
- [1] {System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair 鍵 「X-的Zumo-APPLICATION」 串 值 「FmlVNVhdQhNEAIZZVptKhxlQNuJrlq37」 串 +非公共成員
+ RAW查看
法 「POST」 串 - 烏里{}的System.Uri的System.Uri AbsolutePath 「/.azure-mobile.net/tables/Item」字符串 AbsoluteUri 權威「ichange.azure-mobile.net」字符串 DnsSafeHost「ichange.azure-mobile.net」字符串 Fr agment 「」 串 主機 「ichange.azure-mobile.net」 串 HostNameType System.UriHostNameType.Dns System.UriHostNameType IsAbsoluteUri真布爾 IsDefaultPort真布爾 ISFILE假布爾 IsLoopback假布爾 IsUnc假布爾 了localPath「/ .azure-mobile.net/tables/Item「字符串 OriginalString
PathAndQuery」/.azure-mobile。淨/表/物品」串 端口80 INT 查詢 「」 串 計劃 「HTTP」 串 +區隔{串[4]}串[] UserEscaped假布爾 的UserInfo 「」 串 +靜態成員
+非公共成員
靜態成員

響應 - 響應{Microsoft.WindowsAzure.MobileServices.ServiceFilterResponse} Microsoft.WindowsAzure.MobileServices.ServiceFilterResponse 內容 「{\」 代碼\ 「:404,\」 錯誤\」 :\「Error:Not Found \」}「string Conten tType「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 重點 「的Cache-Control」 的字符串值 「無緩存」 串 +非公共成員
- [1] {System.Collections.Generic。 KeyValuePair} System.Collections.Generic.KeyValuePair 密鑰 「內容長度」 串 值 「39」 的字符串 +非公共成員
- [2] {System.Collections.Generic.KeyValuePair} System.Collections.Generic。柯yValuePair 鍵 「的Content-Type」 字符串值 「應用/ JSON」 串 +非公共成員
- [3] {} System.Collections.Generic.KeyValuePair System.Collections.Generic.KeyValuePair 密鑰 「服務器」串 值 「微軟-IIS/8.0」 字符串 +非公共成員
- [4] {} System.Collections.Generic.KeyValuePair System.Collections.Generic.KeyValuePair 密鑰 「設置Cookie」 的字符串值 「 ARRAffinity = 3041b7170f63e41156a1ff0b65518583e91f68d4f90a680a7750bd8d12f209e0; Path = /; Domain = ichange.a ...「字符串 +非公開成員
- [5] { System.Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair 鍵碼 「x-謨版」 字符串值 「Zumo.Main.0.1.6.3017.Runtime」 串 +非公共成員
- [6 ] {} System.Collections.Generic.KeyValuePair System.Collections.Generic.KeyValuePair 鍵 「X供電,通過」 串 值 「ASP.NET」 串 +非公共成員
- [7] {系統。 Collections.Generic.KeyValuePair} System.Collections.Generic.KeyValuePair Key「Date」string Value「Thu,2013年6月27日18:23:56 GMT」字符串 +非公開成員
+ Raw V IEW
ResponseStatus Microsoft.WindowsAzure.MobileServices.ServiceFilterResponseStatus.ProtocolError Microsoft.WindowsAzure.MobileServices.ServiceFilterResponseStatus 的StatusCode 404 INT 狀態說明「未找到」字符串

+0

什麼是異常對象的細節? – carlosfigueira

+0

@carlosfigueira我編輯的細節問題,我得到的答覆404沒有找到 –

+0

這看起來很奇怪:'string mobileServiceUrl =「http:// MyMoblieService.azure-mobile.net/.azure-mobile.net /' - 你確定你有正確的網址嗎?我真的懷疑它應該有** ./ azure-mobile.net/**域名後... – carlosfigueira

回答

1

正如我們在評論中討論:你傳遞給的網址MobileServiceClient構造函數不正確。 '未找到'的迴應讓我看着你的網址:

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

而這不正確。它應該如下所示:

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

嗨卡洛斯,我看到你在移動服務團隊工作,很棒!!:D如果你有時間,你可以檢查[這個問題](http://stackoverflow.com/questions/18411397/loginasync-missing)嗎?非常感謝! – Marco