0
votes

I want to add an API service to my existing .NET web application.

I was following this tutorial, but couldn't found any option to add web service.

Then I followed these two questions on Stackoverflow (Where is the Global.asax.cs file? and Global.asax file is missing on my Asp.Net Empty Web application project) but couldn't find the Add option for the global application class. How can I resolve this issue? Am I doing something wrong?

I tried to create a new solution, the problem is the same.

  • I'm using VisualStudio 2019 16.4.6

  • My project's targeted framework is .NET Core 3.1

If there is any tutorial or written document for adding web API to an existing project please give me, that would be very helpful. I tried to follow this blog and installed Microsoft.AspNet.WebApi.Core and got this warning -

Package 'Microsoft.AspNet.WebApi.Core 5.2.7' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.

enter image description here

2
Your existing web API project targets to which .net framework?Chetan
I don't have any existing web api projects. I want to add a new api service to may existing web application project (website) which is targeted for .NET Core 3.1Mahmudul Hasan
If you are following a tutorial, follow its every steps. Right now you created a .NET Core project which does not match the .NET Framework project used in that tutorial.Lex Li

2 Answers

3
votes

With ASP.NET Core, the entry point to an application is Startup, and you no longer have a dependency on Global.asax.

You can find more about it on this link

To consume an API you can use RestSharp in your Asp.net Core Application. You can check this link to learn more about consuming an API using RestSharp in your Asp.net Core Application.

1
votes

My project's targeted framework is .NET Core 3.1

Global.asax.cs will not be generated if you use ASP.NET Core. You have to use older version of ASP.NET, for example ASP.NET 4 (4.7.2) if you want to follow that old tutorial.

Or you can try a tutorial for WebApi using Asp.Net Core like this one: https://docs.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-3.1&tabs=visual-studio