5

这是我正在使用的方法。

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. 我已经在 App.XAML.CS 中插入了这段代码。using Microsoft.WindowsAzure.MobileServices;
  4. 我已经将从网站获取的这段代码放在 App.XAML.CS 中。
    public static MobileServiceClient MobileService = new MobileServiceClient( AppUrl, AppKey );

为什么我无法连接到我的数据库?我已经尝试在 Windows Store 应用程序上运行这些代码并且它有效。以前我做过完全相同的事情,而且效果也很好。

4

6 回答 6

3

这个链接救了我。

显然,我所要做的就是将服务地址从 更改httpshttp。所以代替这个,

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

问题解决了。

于 2013-06-04T08:52:05.833 回答
2

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

于 2014-03-16T22:29:59.657 回答
1

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

谢谢纳撒尼尔羊毛!!!

于 2017-04-11T18:44:42.427 回答
0

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

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

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

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

你有没有遇到更多的问题?

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

于 2014-03-06T14:11:13.477 回答
0

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

例如,像这样:

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

于 2015-06-04T02:32:14.090 回答
-1

确保这也被关闭。

在此处输入图像描述

于 2016-04-10T05:47:40.420 回答