尝试从Azure检索数据时MobileServiceInvalidOperationException

时间:2013-06-04 04:39:51

标签: c# azure windows-phone-8

这是我正在使用的方法。

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

需要注意几点。

  1. 权限设置为Anybody with the Application Key
  2. 我添加了对Windows Azure Mobile Services Managed Client
  3. 的引用
  4. 我已经在App.XAML.CS中插入了这段代码。 using Microsoft.WindowsAzure.MobileServices;
  5. 我已经在App.XAML.CS中放置了从this网站获取的这段代码。
    public static MobileServiceClient MobileService = new MobileServiceClient( AppUrl, AppKey );
  6. 为什么我无法连接到我的数据库?我已经尝试在Windows应用商店应用程序上运行这些代码并且它有效。以前我做过完全相同的事情,它也有效。

6 个答案:

答案 0 :(得分: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" 
);

问题解决了。

答案 1 :(得分:2)

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

答案 2 :(得分:1)

我在Android设备中解决了这个问题。您将需要终止您的应用实例,将系统日期/时间更改为当前并重新打开该应用。

感谢Nathanial Woolls !!!

答案 3 :(得分:0)

由于我的声誉很低,我无法发表评论,我遇到了同样的问题,但这是不一致的。

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

我正在使用一个真正的Windows Phone设备,它使用我的iPhone热点提供的Wi-Fi连接,实际上是4G,所以肯定没有连接问题。

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

你有没有遇到任何问题?

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

答案 4 :(得分:0)

如果其他人遇到此问题,我只是简单地将带有错误子域的URL传递给MobileServiceClient时遇到了同样的问题。

例如,像这样:

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

答案 5 :(得分:-1)

确保此功能也已关闭。

enter image description here