![](/img/trans.png)
[英]Getting “TimeoutException” when trying to retrieve data from MongoDB
[英]MobileServiceInvalidOperationException When Trying To Retrieve Data From Azure
这是我正在使用的方法。
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);
}
这是患者实体。
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.<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()
需要注意的几点。
Anybody with the Application Key
将权限设置为Anybody with the Application Key
Windows Azure Mobile Services Managed Client
引用 using Microsoft.WindowsAzure.MobileServices;
public static MobileServiceClient MobileService = new MobileServiceClient( AppUrl, AppKey );
为什么我无法连接到数据库? 我试过在Windows 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设备中解决了此问题。 您将需要杀死您的应用程序实例,将系统日期/时间更改为当前日期,然后重新打开应用程序。
谢谢纳撒尼尔·伍尔斯!
由于声誉低下,我无法发表评论,我也遇到了同样的问题,但是并不一致。
如果我尝试使用我的应用程序中的注册页面打了Azure移动服务,有时它会因相同的错误而超时(“请求无法完成。()”),那么如果我立即重试,它就可以正常工作。
我使用的是实际的Windows Phone设备,并且使用iPhone热点(实际上是4G)提供的Wi-Fi进行连接,因此绝对没有连接问题。
我读过其他文章,说没有必要尝试检查Internet连接是否可用,只是尝试发送数据并处理任何问题。 我处理了这个问题,但是这个问题应该不会发生。
您还有其他问题吗?
我已经尝试过将https和http用于MobileService连接,似乎没有任何区别。
万一其他人遇到这个问题,当我只是简单地将一个带有错误子域的URL传递给MobileServiceClient时,我就会遇到相同的问题。
例如,如下所示:
public static MobileServiceClient MobileService = new MobileServiceClient( "http://www.example.azure-mobile.net/", "fjkdslajkfdlsref31321fgdsat34ajklfdslajfkldsa" );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.