I'm writing a Windows Phone 8.1 Store App to help manage the public transport of my small town as a project for my Univerisity.
The professor asked me to create this app implementing a Web Service and a SQL Database.
After some research I decided to use Windows Azure with a SQL Database. The database only consists of one simple table that holds the bus stops (each one has an Id, Name, Latitude and Longitude).
If I execute a query I have no problems with result. However, problems start then I try to connect my project to the Web Service & the associated database.
I created che client in the project, as suggested in a Microsoft tutorial, as following:
public static Microsoft.WindowsAzure.MobileServices.MobileServiceClient RapalloBusClient = new Microsoft.WindowsAzure.MobileServices.MobileServiceClient(
"https://<mywebservicename>.azure-mobile.net/",
"xxxxxxxxxxxxxxxxxxxxxxxxxxxx");
Doing this Visual Studio added my solution another project called <mywebservicename>MobileService
, and that had a class Todoitem.cs in a DataObjects folder, and a TodoitemController.cs in a Controllers folder.
I then modified these classes for my solution.
Now to test if I'm doing all right I tried to print in a ListBox
of all elements of my database (there is only one actually: a bus stop with Id=1, the name, and its coordinates).
The code that I use is (fermate=bus stops in italian):
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;
}
This code is generating an error ("Internal server error" or "not found") and I can not figure out where it wrong.
I'm using the tutorial at the following link https://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-windows-universal-dotnet-get-started-data/, and with the solution attached, I didn't have any problems
Edit:
I connect the Mobile Service to the database using settings menù of <mywebservicename>MobileServiceMobile
project in visual studio (In "Pubblicazione/Creazione pacchetto SQL" section (in italian) I check the option that say "extract data/schema from an existing database" providing the database url from Azure).
I removed the breakpoints a let the app run, but when I execute the following line I run in an exception:
fermate = await fermateTable.ToCollectionAsync();
The expception is the following:
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:
My suspicion is that this is an Entity Framework issue on the server. The server will throw on data operations if the schema does not match what it expects, etc. Did you modify the DbContext associated with your table?
You will need to ensure that the server has a model of the database schema (your modified TodoItem.cs) and that Entity Framework is able to resolve it appropriately. Please see this a tutorial for working with an existing SQL database: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-dotnet-backend-use-existing-sql-database/
One thing you can do to help isolate this issue is to try accessing your endpoints without the client. If you use Fiddler/Postman or similar, you can try an HTTP GET or POST on /tables/fermate to see if the fermate TableController code is working with your actual database. You can also use the "try it now" link on the root page for your service to send test calls. If prompted for a password, this is generally your Application Key (no username).