Asp.net Core and create a webservice (asmx) [duplicate]

ⅰ亾dé卋堺 提交于 2019-12-06 16:00:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!