尝试从Azure检索数据时MobileServiceInvalidOperationException
这是我正在使用的方法。
try { List pList = await App.MobileService.GetTable().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); }
这是患者实体。
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; } }
这是我得到的错误。
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
当我在TryCatch中包装我的方法时,我收到此消息
Error : The request could not be completed. ()
这是堆栈错误消息
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.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.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.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.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.d__0.MoveNext()
有几点需要注意。
-
Anybody with the Application Key
将权限设置为Anybody with the Application Key
- 我添加了对
Windows Azure Mobile Services Managed Client
引用 - 我已经在App.XAML.CS中插入了这段代码。
using Microsoft.WindowsAzure.MobileServices;
- 我已经在App.XAML.CS中放置了从这个网站获得的这段代码。
public static MobileServiceClient MobileService = new MobileServiceClient( AppUrl, AppKey );
为什么我无法连接到我的数据库? 我已经尝试在Windowsapp store应用程序上运行这些代码,但它确实有效。 以前我做过完全相同的事情,它也有效。
这个链接救了我。
显然,我所要做的就是将服务地址从https
更改为http
。 所以不是这样,
public static MobileServiceClient MobileService = new MobileServiceClient( "https://www.example.azure-mobile.net/", "fjkdslajkfdlsref31321fgdsat34ajklfdslajfkldsa" );
将其更改为
public static MobileServiceClient MobileService = new MobileServiceClient( "http://www.example.azure-mobile.net/", "fjkdslajkfdlsref31321fgdsat34ajklfdslajfkldsa" );
问题解决了。
检查计算机或设备上的日期/时间。 在我的情况下,我已经打开了已经关闭一段时间的开发电话,日期/时间完全错误。 虽然将端点从HTTPS更改为HTTP确实解决了这个问题,但对我来说,正确的解决方案是保留HTTPS并修复设备上的日期/时间。
我在Android设备中解决了这个问题。 您将需要终止您的应用实例,将系统日期/时间更改为当前并重新打开该应用。
谢谢Nathanial Woolls !!!
我不能发表评论,因为我的声誉很低,我遇到了同样的问题,但这是不一致的。
如果我尝试使用我的应用程序上的注册页面访问Azure移动服务,有时它会超时相同的错误(“请求无法完成。()”),然后如果我立即再次尝试它工作正常。
我正在使用一个真正的Windows Phone设备,它使用我的iPhone热点提供的Wi-Fi连接,实际上是4G,所以肯定没有连接问题。
我读过其他文章,说没有必要尝试检查互联网连接是否可用,只是尝试发送数据并处理任何问题。 我处理这个问题,但问题不应该发生。
你有没有遇到任何问题?
我尝试过使用https和http作为MobileService连接,似乎没什么区别。
如果其他人碰到这个,我只是简单地将一个带有错误子域的URL传递给MobileServiceClient时遇到了同样的问题。
例如,像这样:
public static MobileServiceClient MobileService = new MobileServiceClient( "http://www.example.azure-mobile.net/", "fjkdslajkfdlsref31321fgdsat34ajklfdslajfkldsa" );
确保此function也已关闭。