[英]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 当我将方法包装在TryCatch中时,我收到此消息
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. 需要注意的几点。
Anybody with the Application Key
Anybody with the Application Key
将权限设置为Anybody with the Application Key
Windows Azure Mobile Services Managed Client
Windows Azure Mobile Services Managed Client
引用 using Microsoft.WindowsAzure.MobileServices;
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.
我试过在Windows Store应用程序上运行这些代码,并且可以正常工作。 Previously i've done the exact same thing and it worked as well.
以前我做过完全相同的事情,而且效果也很好。
Apparently, all i had to do is to change the service address from https
to http
. 显然,我要做的就是将服务地址从
https
更改为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. 问题解决了。
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.
虽然将端点从HTTPS更改为HTTP确实可以解决该问题,但对我而言,正确的解决方案是保留HTTPS并修复设备上的日期/时间。
I solved this problem in my Android devices. 我在Android设备中解决了此问题。 You will need kill your app instance, change the system date/time to current and reopen the app.
您将需要杀死您的应用程序实例,将系统日期/时间更改为当前日期,然后重新打开应用程序。
Thanks Nathanial Woolls!!! 谢谢纳撒尼尔·伍尔斯!
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. 如果我尝试使用我的应用程序中的注册页面打了Azure移动服务,有时它会因相同的错误而超时(“请求无法完成。()”),那么如果我立即重试,它就可以正常工作。
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. 我使用的是实际的Windows Phone设备,并且使用iPhone热点(实际上是4G)提供的Wi-Fi进行连接,因此绝对没有连接问题。
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. 我读过其他文章,说没有必要尝试检查Internet连接是否可用,只是尝试发送数据并处理任何问题。 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. 我已经尝试过将https和http用于MobileService连接,似乎没有任何区别。
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. 万一其他人遇到这个问题,当我只是简单地将一个带有错误子域的URL传递给MobileServiceClient时,我就会遇到相同的问题。
For instance, something like this: 例如,如下所示:
public static MobileServiceClient MobileService = new MobileServiceClient( "http://www.example.azure-mobile.net/", "fjkdslajkfdlsref31321fgdsat34ajklfdslajfkldsa" );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.