2017-02-13 34 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:处理大文件上传

如果你正在做一个插入,你的数据不应该那么大。不要将图像或其他较大的项目插入表格 - 这是一种不好的做法。