2016-06-28 9 views
1

私は興味があります。Azure Mobile Appサービスの例外 "アイテムが存在しません" InsertAsync

public class InmeItem 
{ 
     public string Id { get; set; } 
     [JsonProperty(PropertyName = "heartrate")] 
     public string Heartrate { get; set; } 
     [JsonProperty(PropertyName = "pulsewave")] 
     public string Pulsewave { get; set; } 
} 

私はテーブルに新しい項目を挿入するフォローコードを持っている:私はクラスとAzureの上のテーブル持って

public static async Task InsertInmeItem(InmeItem inmeitem) 
{ 
    try 
    { 
     await App.MobileService.GetTable<InmeItem>().InsertAsync(inmeitem); 
    } 

    catch (Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException ex) 
    { 
      Debug.WriteLine("This is f***** situation which post data but generate exception: " + ex.ToString()); 
    } 

    catch (Exception ex) 
    { 
      Debug.WriteLine(ex); 
    } 
} 

をしかし、私はいくつかの興味を持って状況持っている - ランニングスロー例外を「項目にはありません

存在」が、データはすべての例外なしのAzure上の表に挿入された例外情報:

This is f***** situation which post data but generate exception: Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: The item does not exist 
    at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.<ThrowInvalidResponse>d__18.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.<SendRequestAsync>d__1d.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.<RequestAsync>d__4.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.<>c__DisplayClass14.<<InsertAsync>b__13>d__16.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.<TransformHttpException>d__4d.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.<InsertAsync>d__1a.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.WindowsAzure.MobileServices.MobileServiceTable`1.<TransformHttpException>d__41.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.WindowsAzure.MobileServices.MobileServiceTable`1.<InsertAsync>d__b.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at Microsoft.WindowsAzure.MobileServices.MobileServiceTable`1.<InsertAsync>d__5.MoveNext() 
--- End of stack trace from previous location where exception was thrown --- 
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 
    at System.Runtime.CompilerServices.TaskAwaiter.GetResult() 
    at InmeTesting.Models.Backoffice.<InsertInmeItem>d__2.MoveNext() 

答えて

3

がスローされます。必ずしも挿入されたアイテムを返す必要はありませんが、クライアントにレンダリングするために何かを返さなければなりません。そうしないと、フレームワークは "アイテムは存在しません"というメッセージとともに404を返します。

context.executeが挿入された項目を返すため、最初の例は成功します。 2番目の例では、項目が明らかに.then()呼び出しのコードブロックから返されていません。

0

私は理由を見つけました。

  • Theese例外このexeptionのために

    は2つの理由

    1. クラウド上の表のデータベースと名前のクラスのの等しくない名前かもしれ(ただし、クラスが同じである)もあれば投げますバックエンドで(私の場合には、これはノードJSある)table.insert(function (context) {...});return context.execute();試験を受験する

    then()がありますこのコード

    table.insert(function (context) { 
        //context.item.userId = context.user.id; 
    
        //Retranslate data to inme server 
        retranslateToInme(context.item.heartrate, context.item.pulsewave); 
    
        return context.execute(); 
    }); 
    

    例外をスローしないでください。しかし:

    table.insert(function (context) { 
        //context.item.userId = context.user.id; 
    
        //Retranslate data to inme server 
        retranslateToInme(context.item.heartrate, context.item.pulsewave); 
    
        return context.execute().then(...); 
    }); 
    

    はあなたがinsert関数から正しい結果を返すされている、すなわち、それはあなたが挿入されたアイテムを返すように期待していることを確認する必要があり、例外

  • 関連する問題