I created an ASP.NET Web Application - Azure Mobile App project in Visual Studio. I haven't modified anything, so it has the default todo item controller. If I run the program locally and use a REST client to request a GET action from
localhost:port/tables/TodoItem
with the header ZUMO-API-VERSION set at 2.0.0 everything works perfectly. I published the app to Azure and when I try to request a GET action from
MYLINK.azurewebsites.net/tables/TodoItem
with the header ZUMO-API-VERSION set at 2.0.0 I get (after about 1 minute) a "500 Internal Sever Error" with the message "An error has occurred." If I don't add the header I get almost instantly the "400 Bad Request" saying that I have to specify the API version. Am I doing something wrong? What causes this problem and how can I solve it?
The error was happening because the default project that Azure creates for the back-end is intended to be used with SQL. You could leverage KUDU or Azure App Service Editor to check your MS_TableConnectionString
connectionstring under your web.config file. The connectionstring would look like this:
<add name="MS_TableConnectionString" connectionString="Server=tcp:{your_dbservername}.database.windows.net,1433;Initial Catalog={your_dbname};Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;" providerName="System.Data.SqlClient"/>
When deploy your mobile app to Azure via Visual Studio, you need to point your connectionstring to your Azure db as follows:
For more details about creating and deploying your mobile app to Azure App Service, you could refer to this document. Also, you could leverage "All Settings > Application settings" under your web app blade to configure your connectionstring, which could override your existing connectionstring in your web.config file at runtime. For more details, you could follow this official tutorial.
After configuring that, you will work well.
Additionally, you could follow Adrian Hall's book here for a better understanding and a quick start with Azure Mobile Apps.