2013-06-04 110 views
5

这是我正在使用的方法。MobileServiceInvalidOperationException尝试从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); 
} 

这是Patient实体。

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() 

有几点要注意。

  1. 权限设置为Anybody with the Application Key
  2. 我已经添加参考Windows Azure Mobile Services Managed Client
  3. 我已经插入内App.XAML.CS.验证码using Microsoft.WindowsAzure.MobileServices;
  4. 我已经把这段从this网站获得的代码放在App.XAML.CS中。
    public static MobileServiceClient MobileService = new MobileServiceClient(AppUrl, AppKey);

为什么我无法连接到我的数据库?我试过在Windows应用商店应用程序上运行这些代码,它工作。以前我做了完全相同的事情,它也起作用。

回答

3

This链接救了我。

显然,我所要做的就是将服务地址从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" 
); 

问题解决了。

+2

这并不“解决”问题,它可以解决问题。这会禁用HTTPS,这意味着您的数据现在以明文形式发送 - 可能不是一件好事。在我的情况下,日期/时间是错误的设备,使HTTPS失败。 –

0

我不能评论,因为我的名誉低,我遇到同样的问题,但它不一致。

如果我尝试在我的应用上使用注册Azure移动服务的注册页面,有时会出现相同的错误(“请求无法完成。()”),那么如果我立即再试一次它工作正常。

我使用的是实际的Windows Phone设备,它使用我的iPhone热点提供的Wi-Fi进行连接,而这个热点实际上是4G,所以绝对不存在连接问题。

我读过其他一些文章,说试图检查互联网连接是否可用,只是尝试发送数据并处理任何问题。我处理这个问题,但这个问题不应该发生。

您是否遇到过更多问题?

我已经尝试使用https和http为MobileService连接,似乎没有任何区别。

+0

有没有人有任何想法? – xceed

2

检查计算机或设备上的日期/时间。在我的情况下,我使用了一段时间关闭的开发电话,日期/时间完全错误。虽然将端点从HTTPS更改为HTTP确实可以解决此问题,但对于我来说,正确的解决方案是保持HTTPS并在设备上修复日期/时间。

+0

这是正确的答案。仅仅因为测试设备不好,您不应该禁用https。 –

0

万一有其他人遇到这种情况,我遇到同样的问题,当我只是简单地通过一个URL不正确的子域到MobileServiceClient。

举例来说,这样的事情:

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

1

我在Android设备解决了这个问题。您需要杀死您的应用程序实例,将系统日期/时间更改为最新并重新打开该应用程序。

谢谢Nathanial Woolls !!!

相关问题