0
votes

I'm using Azure mobile services with .net backend, with MvvmCross using Xamarin Pcl based solution. The service returns me the results when I run it interactively from the default browser interface provided by Azure Mobile Services. Also I'm using offline data sync feature. I can push the data to the server and it works but now when I try to pull the data from the server.

{Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: The request could not be completed. () at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.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 System.Runtime.CompilerServices.TaskAwaiter.GetResult()
at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.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 System.Runtime.CompilerServices.TaskAwaiter1.GetResult() 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 System.Runtime.CompilerServices.TaskAwaiter1.GetResult() at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.d__f.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.TaskAwaiter1.GetResult() at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.<ReadAsync>d__7.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.TaskAwaiter1.GetResult() at Microsoft.WindowsAzure.MobileServices.Sync.PullAction.d__0.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 Microsoft.WindowsAzure.MobileServices.Sync.TableAction.d__0.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 Microsoft.WindowsAzure.MobileServices.Sync.MobileServiceSyncContext. d__3b.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 Microsoft.WindowsAzure.MobileServices.Sync.MobileServiceSyncContext.d__27.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 AgLiveMobile.Core.Services.EmployeeService.d__4.MoveNext()}

I even did debug the service from client to server and the result are comings but I'm unable to get any idea why this happens. I'm testing on my Windows Phone 8.1 device with Wifi connection on.

Please help.

2

2 Answers

10
votes

After further analyzing the http response in the exception dialog of VS. The actual error was 404 Not found. Then further debugging the issue it turned out to be that the application url of Azure Mobile Services should be https and not http

It would be good if the product team can find this out and give proper error message, which can save lot of time and devs doesn't get frustrated.

0
votes

I had the same issue, but my problem was, that the UpdateAsync tries to get an item which doesn't exists in my database.

I have solved this issue with the SyncHandler and the following catch block:

                catch (Exception ex) when (ex is MobileServiceInvalidOperationException)
                {
                    var error = (MobileServiceInvalidOperationException)ex;

                    if (operation.Kind != MobileServiceTableOperationKind.Update)
                    {
                        continue;
                    }

                    if (error.Response.StatusCode != HttpStatusCode.NotFound)
                    {
                        continue;
                    }

                    var azureMobileBackend = new AzureMobileBackend();

                    var table = await azureMobileBackend.GetSyncTable<...>();
                    await table.PurgeAsync(null, table.Where(x => x == operation.Item.ToObject<...>()), new CancellationToken());
                }

With my code, I check, whether Mobile Apps tries to update an object which doesn't exist in the database and if, delete it in the local database. I'm not sure, whether this is the best way, but it is okay for my case.

I think the problem cause, if the application is shutting down, while the UpdateAsync method is working.