![](/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.