Jieqin
Jieqin

Reputation: 588

MobileServiceInvalidOperationException When Trying To Retrieve Data From Azure

This is the method i am using.

try
{
    List<Patient> pList = await App.MobileService.GetTable<Patient>().Where(
                patient => patient.id == 1).ToListAsync();
    foreach (Patient p in pList)
    {
        System.Diagnostics.Debug.WriteLine("{0}, {1}", p.id, p.first_name);
    }
}
catch (Exception err)
{
    System.Diagnostics.Debug.WriteLine("ERROR! : {0}", err.Message);
}

Here's the Patient entity.

class Patient
{
    public int id { get; set; }
    public string first_name { get; set; }
    public string last_name { get; set; }
    public string middle_name { get; set; }
    public string nirc { get; set; }
    public int bed_id { get; set; }
}

Here's the error i am getting.

An exception of type 'System.Net.WebException' occurred in System.Windows.ni.dll and     wasn't handled before a managed/native boundary
An exception of type 'System.Net.WebException' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary
An exception of type 'System.Net.WebException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
An exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.DLL and wasn't handled before a managed/native boundary
An exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in Microsoft.Azure.Zumo.WindowsPhone8.Managed.DLL and wasn't handled before a managed/native boundary
An exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
An exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
An exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary
A first chance exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in mscorlib.ni.dll
An exception of type 'Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary

When i wrap my method within a TryCatch, i get this message

Error : The request could not be completed.  ()

Here's the stack error message

    at Microsoft.WindowsAzure.MobileServices.MobileServiceClient.CreateMobileServiceException(String errorMessage, IServiceFilterRequest request, IServiceFilterResponse response)
    at Microsoft.WindowsAzure.MobileServices.MobileServiceClient.ThrowInvalidResponse(IServiceFilterRequest request, IServiceFilterResponse response, JToken body)
    at Microsoft.WindowsAzure.MobileServices.MobileServiceClient.<RequestAsync>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.TaskAwaiter`1.GetResult()
    at Microsoft.WindowsAzure.MobileServices.MobileServiceTable.<SendReadAsync>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`1.GetResult()
    at Microsoft.WindowsAzure.MobileServices.MobileServiceTable`1.<EvaluateQueryAsync>d__3`1.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`1.GetResult()
    at Microsoft.WindowsAzure.MobileServices.MobileServiceTableQuery`1.<ToListAsync>d__2.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`1.GetResult()
    at PhoneApp1.MainPage.<populate>d__0.MoveNext()

A few points to note.

  1. Permission is set to Anybody with the Application Key
  2. I've added reference to Windows Azure Mobile Services Managed Client
  3. I've already inserted this code within App.XAML.CS. using Microsoft.WindowsAzure.MobileServices;
  4. I've already placed this piece of code acquired from this website within App.XAML.CS.
    public static MobileServiceClient MobileService = new MobileServiceClient( AppUrl, AppKey );

Why am i unable to connect to my database? I've tried running these codes on a Windows Store Application and it worked. Previously i've done the exact same thing and it worked as well.

Upvotes: 5

Views: 6305

Answers (6)

&#194;ngelo Polotto
&#194;ngelo Polotto

Reputation: 9511

I solved this problem in my Android devices. You will need kill your app instance, change the system date/time to current and reopen the app.

Thanks Nathanial Woolls!!!

Upvotes: 1

Emil
Emil

Reputation: 6891

Make sure that also this is turned off.

enter image description here

Upvotes: -1

neoncube
neoncube

Reputation: 73

In case anyone else runs into this, I experienced the same issue when I simply had simply passed a URL with an incorrect subdomain to MobileServiceClient.

For instance, something like this:

public static MobileServiceClient MobileService = new MobileServiceClient( 
    "http://www.example.azure-mobile.net/", 
    "fjkdslajkfdlsref31321fgdsat34ajklfdslajfkldsa" 
);

Upvotes: 0

Nathanial Woolls
Nathanial Woolls

Reputation: 5291

Check the date / time on your computer or the device. In my case I had powered on a dev phone that had been off for some time and the date / time was completely wrong. While changing the endpoint from HTTPS to HTTP does work around the issue, for me the proper solution was to keep HTTPS and fix the date / time on the device.

Upvotes: 2

xceed
xceed

Reputation: 140

I can't comment because of my low reputation, I'm experiencing the same problem, but it's inconsistent.

If I try to use the registration page on my app that hits an Azure Mobile Service, sometimes it times out with the same error ("The request could not be completed. ()"), then if I try again immediately it works fine.

I'm using an actual Windows Phone Device and it's connected using Wi-Fi provided by my iPhone's hotspot which is actually 4G so there's definitely not a connection issue.

I read other articles that said there's no point trying to check if an internet connection is available, just try and send the data and deal with any issues. I deal with the issue but the issue shouldn't be happening.

Did you experience any more problems?

I've tried using https and http for the MobileService connection, doesn't seem to make any difference.

Upvotes: 0

Jieqin
Jieqin

Reputation: 588

This link saved me.

Apparently, all i had to do is to change the service address from https to http. So instead of this,

public static MobileServiceClient MobileService = new MobileServiceClient( 
    "https://www.example.azure-mobile.net/", 
    "fjkdslajkfdlsref31321fgdsat34ajklfdslajfkldsa" 
);

Change it to

public static MobileServiceClient MobileService = new MobileServiceClient( 
    "http://www.example.azure-mobile.net/", 
    "fjkdslajkfdlsref31321fgdsat34ajklfdslajfkldsa" 
);

Problem solved.

Upvotes: 3

Related Questions