1

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

Mahmudul Hasan
  • 798
  • 11
  • 35
  • Your existing web API project targets to which .net framework? – Chetan Mar 14 '20 at 07:16
  • 1
    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.1 – Mahmudul Hasan Mar 14 '20 at 07:19
  • 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 Mar 14 '20 at 13:41

2 Answers2

3

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.

Pramil Gawande
  • 455
  • 8
  • 13
1

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://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-3.1&tabs=visual-studio

Andrej Lucansky
  • 725
  • 10
  • 17