问题
With previous version of .net, I used right click on project , add file and then I can create a file name "Web Service(asmx)" and then I create my webservice and differents function needed.
But I don't understand how on a new projet .net core, I create the same files to my project?
thank you in advance for your help
回答1:
In Asp.net Core there are no separate Web Api's or Web forms, there is just ASP.Net Core MVC.
Api's are implemented in the same way as MVC using controllers and actions. You just return the response instead of view. Or if you can still return the view containing the response. . For example
[HttpGet("{id}", Name = "GetTodo")] //Name used when calling the api
public IActionResult GetById(string id)
{
var item = TodoItems.Find(id);
if (item == null)
{
return NotFound();
}
return new ObjectResult(item);
}
These API's can be called through Http just like asmx.You dont need asmx anymore. For more info see this link
回答2:
ASMX as a technology has been supplanted with newer things in .NET, such as MVC and WebAPI. I'd look into using one of these (probably WebAPI) to create web services in .NET core.
来源:https://stackoverflow.com/questions/39079338/asp-net-core-and-create-a-webservice-asmx