【问题标题】:MobileServiceInvalidOperationException When Trying To Retrieve Data From Azure尝试从 Azure 检索数据时出现 MobileServiceInvalidOperationException
【发布时间】:2017-04-12 02:44:42
【问题描述】:

这是我正在使用的方法。

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 应用商店应用程序上运行这些代码并且它有效。以前我做过完全相同的事情,而且效果也很好。

【问题讨论】:

    标签: c# azure windows-phone-8


    【解决方案1】:

    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" 
    );
    

    问题解决了。

    【讨论】:

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

    检查您的计算机或设备上的日期/时间。就我而言,我打开了一部已经关闭一段时间的开发手机,并且日期/时间完全错误。虽然将端点从 HTTPS 更改为 HTTP 确实可以解决此问题,但对我而言,正确的解决方案是保留 HTTPS 并修复设备上的日期/时间。

    【讨论】:

    • 这是正确答案。您不应该仅仅因为测试设备不好而禁用 https。
    • 只删除数据库和应用
    【解决方案3】:

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

    感谢纳撒尼尔羊毛!!!

    【讨论】:

      【解决方案4】:

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

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

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

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

      您是否遇到了更多问题?

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

      【讨论】:

      • 有人有什么想法吗?
      【解决方案5】:

      万一其他人遇到这种情况,我只是简单地将带有错误子域的 URL 传递给 MobileServiceClient 时遇到了同样的问题。

      例如,像这样的:

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

      【讨论】:

        【解决方案6】:

        确保也将其关闭。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2023-03-17
          • 1970-01-01
          • 1970-01-01
          • 2016-07-08
          • 2013-05-15
          • 2010-11-15
          • 2013-04-17
          • 2021-10-02
          相关资源
          最近更新 更多