我正在编写一个Windows Phone 8.1商店应用程序,以帮助管理我的小镇的公共交通工具,作为我的大学项目。
教授让我创建这个实现Web服务和SQL数据库的应用程序。
经过一番研究后,我决定将Windows Azure与SQL数据库结合使用。数据库只包含一个保存公交车站的简单表(每个公交站都有一个Id,Name,Latitude和Longitude)。
如果我执行查询,结果没有问题。然而,问题开始然后我尝试将我的项目连接到Web服务&相关的数据库。
我按照Microsoft教程中的建议在项目中创建了che客户端,如下所示:
public static Microsoft.WindowsAzure.MobileServices.MobileServiceClient RapalloBusClient = new Microsoft.WindowsAzure.MobileServices.MobileServiceClient(
"https://<mywebservicename>.azure-mobile.net/",
"xxxxxxxxxxxxxxxxxxxxxxxxxxxx");
执行此操作Visual Studio为我的解决方案添加了另一个名为<mywebservicename>MobileService
的项目,它在DataObjects文件夹中有一个类Todoitem.cs,在Controllers文件夹中有一个TodoitemController.cs。
然后我为我的解决方案修改了这些类。
现在测试我是否做得很好我尝试在我的数据库的所有元素的ListBox
中打印(实际上只有一个:Id = 1的公共汽车站,名称及其坐标)。
我使用的代码是(fermate =意大利语的公共汽车站):
MobileServiceInvalidOperationException exception = null;
try
{
fermate = await fermateTable.ToCollectionAsync();
}
catch (MobileServiceInvalidOperationException ex)
{
exception = ex;
}
if (exception != null)
{
await new MessageDialog(exception.Message, "Error loading items").ShowAsync();
}
else
{
lstBox.ItemsSource = fermate;
}
此代码生成错误(“内部服务器错误”或“未找到”),我无法弄清楚错误的位置。
我正在使用以下链接https://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-windows-universal-dotnet-get-started-data/中的教程,并附带解决方案,我没有任何问题
编辑:
我使用visual studio中<mywebservicename>MobileServiceMobile
项目的设置menù将移动服务连接到数据库(在“Pubblicazione / Creazione pacchetto SQL”部分(意大利语)中)我检查说“从中提取数据/模式”的选项现有数据库“从Azure提供数据库URL。”
我删除了断点,让app运行,但是当我执行以下行时,我运行异常:
fermate = await fermateTable.ToCollectionAsync();
表示如下:
Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException non è stata gestita dal codice utente
HResult=-2146233079
Message=The request could not be completed. (Internal Server Error)
Source=Microsoft.WindowsAzure.Mobile
StackTrace:
at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.<ThrowInvalidResponse>d__18.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.GetResult()
at Microsoft.WindowsAzure.MobileServices.MobileServiceHttpClient.<SendRequestAsync>d__1d.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.MobileServiceHttpClient.<RequestAsync>d__4.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.<ReadAsync>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.<ReadAsync>d__7.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.Query.MobileServiceTableQueryProvider.<Execute>d__8`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.Query.MobileServiceTableQueryProvider.<Execute>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.MobileServiceCollection`2.<ProcessQueryAsync>d__6.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.MobileServiceCollection`2.<LoadMoreItemsAsync>d__c.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.MobileServiceCollectionExtensions.<ToCollectionAsync>d__0`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 AppBus.CustomImagePage.<AppBarButton_Click>d__1e.MoveNext()
InnerException:
答案 0 :(得分:2)
我怀疑这是服务器上的实体框架问题。如果架构与预期的架构不匹配,服务器将抛出数据操作。您是否修改了与表关联的DbContext?
您需要确保服务器具有数据库模式的模型(您修改的TodoItem.cs),并且实体框架能够适当地解析它。请参阅此教程以使用现有SQL数据库:https://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-use-existing-sql-database/
您可以做的一件事就是尝试在没有客户端的情况下访问您的终端。如果您使用Fiddler / Postman或类似的,您可以在/ tables / fermate上尝试HTTP GET或POST,以查看fermate TableController代码是否与您的实际数据库一起使用。您也可以使用&#34;立即尝试&#34;链接在根页面上,以便您的服务发送测试呼叫。如果提示输入密码,通常是您的应用程序密钥(无用户名)。