500 error code when calling published API to Azure:
Steps to create Api project (works locally):
- open Visual Studio 2022
- choose API project on windows
- weather forecast api project automatically generated, has Swagger integrated
- tested locally, works OK: https://localhost:7264/swagger/index.html // has a single get request, avalable at: https://localhost:7264/WeatherForecast
Steps to deploy to Azure:
from VS, right click on project, Publish
target = Azure
Azure service used to host app: "Azure App Service (Windows)"
choose subscription
create new (App Service): give it a name (wfappservice), choose existing resource group, create hosting plan with Size S1.
In the "Api Management" section - create new instance: WFA1api; API URL suffix: wf
Go to Azure portal - RG selected earlier - find here the API Management created earlie i.e. WFA1api
Inside the API Management service, choose APIs - choose the WFA1api instance - right click it - choose Import API - browse to the OpenAPI specification (json file downloaded earlier from the Swagger page from the local project) - click Import
To test, go to the TEST tab (from the same API Management service instance) - click on the GET request (shows up here from the OpenAPI specification file imported on the previous step) - click on SEND on the request -> I get error 500:
{ "statusCode": 500, "message": "Internal server error", "activityId": "f773cfca-45a4-4a2f-b1ed-96d1ef2ef66f" }
On the TRACE tab, I see:
Trace is not available because response does not contain Ocp-Apim-Trace-Location header.
Any idea on how I can solve or debug this error? And how do I make the Api call if I skip the Api Management step, what is the procedure in that case? What if my project also has a database?
Thank you
CodePudding user response:
I have deploy an App service with API management follow the below steps
Open visual Studio and create a sample
ASP.NET Core API
and run it locally as below.
- Now deploy it to azure portal Right Click on Project ->Click on Publish
- Select the Windows as below
- Click on Create and fill the required details as below and click on next.
- Click on Create to API management as below.
- Fill the required details as below and click on Create
- Select the API and web application and click on finish and then click on close
- After that click on Publish
Note: In some cases, the APi is not deploying into App service in that case follow below steps.
- After Deployment GOTO Resource group open App service and Api management. Select your API management as below and click on link.
- Follow the steps as below.
- After that GOTO App service and -> GOTO Api management as shown below.