2017-02-13 33 views
0

問題

如何解決,我已經在微軟的Azure門戶創建了一個簡單的表此錯誤消息?當我打電話MobileServiceClient.SyncContext.PushAsync出現此錯誤:Azure的簡易表:請求實體太大

OperationKind: Insert 

Error Result: { 
    "error": "request entity too large" 
} 

的NuGet軟件包

我使用下面的NuGet包:

  • Microsoft.Azure.Mobile.Client V3.1.0
  • 微軟。 Azure.Mobile.Client.SQLiteStore v3.1.0

代碼

static bool _isInitialized; 
    static MobileServiceClient _mobileService; 

    public static async Task<IEnumerable<T>> GetItemsAsync<T>() where T : EntityData 
    { 
     await Initialize<T>(); 

     await SyncItemsAsync<T>(); 

     return await _mobileService.GetSyncTable<T>().ToEnumerableAsync(); 
    } 

    public static async Task<T> GetItem<T>(string id) where T : EntityData 
    { 
     await Initialize<T>(); 

     await SyncItemsAsync<T>(); 

     return await _mobileService.GetSyncTable<T>().LookupAsync(id); 
    } 

    public static async Task AddItemAsync<T>(T item) where T : EntityData 
    { 
     await Initialize<T>(); 

     await _mobileService.GetSyncTable<T>().InsertAsync(item); 
     await SyncItemsAsync<T>(); 
    } 

    public static async Task UpdateItemAsync<T>(T item) where T : EntityData 
    { 
     await Initialize<T>(); 

     await _mobileService.GetSyncTable<T>().UpdateAsync(item); 
     await SyncItemsAsync<T>(); 
    } 

    public static async Task RemoveItemAsync<T>(T item) where T : EntityData 
    { 
     await Initialize<T>(); 

     await _mobileService.GetSyncTable<T>().DeleteAsync(item); 
     await SyncItemsAsync<T>(); 
    } 

    static async Task SyncItemsAsync<T>() where T : EntityData 
    { 
     await Initialize<T>(); 

     try 
     { 
      await _mobileService.SyncContext.PushAsync(); 
      await _mobileService.GetSyncTable<T>().PullAsync($"all{typeof(T).Name}", _mobileService.GetSyncTable<T>().CreateQuery()); 
     } 
     catch (Exception ex) 
     { 
      System.Diagnostics.Debug.WriteLine($"Error during Sync occurred: {ex.Message}"); 
     } 
    } 

    async static Task Initialize<T>() where T : EntityData 
    { 
     if (_isInitialized) 
      return; 

     _mobileService = new MobileServiceClient(AzureConstants.AppServiceUrl); 

     await ConfigureOnlineOfflineSync<T>(); 

     _isInitialized = true; 
    } 

    static async Task ConfigureOnlineOfflineSync<T>() where T : EntityData 
    { 
     var path = Path.Combine(MobileServiceClient.DefaultDatabasePath, "azureSyncDatabase.db"); 
     var store = new MobileServiceSQLiteStore(path); 
     store.DefineTable<T>(); 

     await _mobileService.SyncContext.InitializeAsync(store, new SyncHandler(_mobileService)); 
    } 
+0

這有幫助嗎? http://stackoverflow.com/questions/36496043/azure-app-service-limits-body-size-to-64kb – Krumelur

+0

嘿@Krumelur!這是有道理的,但我不知道如何配置後端,因爲我使用了Azure Easy Tables,而且我沒有手動創建API。 –

回答

1

Azure移動應用程序後端只是一個Node.js站點,爲您預先配置。您可以使用App Service Editor查看幕後代碼。

看看Azure Mobile Apps Node.js HOWTO - 它包含一個部分,使有效負載的大小接受更大。只需在App Service Editor中實施更改並重新啓動服務即可。尋找HOWTO:處理大文件上傳

如果你正在做一個插入,你的數據不應該那麼大。不要將圖像或其他較大的項目插入表格 - 這是一種不好的做法。