What are the main differences in functionality between these two method attributes?
[HttpPost]
is an Attribute that decorates a controller or controller action in ASP.Net MVC. You will use it to only allow a request to enter this action method if it is of type "POST".
It looks like this typically:
[HttpPost]
public ActionResult MyControllerAction()
{
// only can get here if httprequest was a "POST"
}
A [WebMethod]
attribute is used to decorate methods on an old school .asmx page typically used for making a web service. Attaching the [WebMethod]
attribute to a Public method indicates that you want the method exposed as part of the XML Web service.
Typically looks like this on an .asmx page:
public class Service1 : System.Web.Services.WebService
{
[WebMethod] // exposes XML Web Service Method
public DataSet IAmAWebServiceMethod()
{
//implementation code
}
}
They are not comparable and do completely different operations. One handles "POST" requests for a web application while another exposes a XML Web Service method.
There is no comparison between them. [WebMethod]
is part of the legacy ASMX web service technology and should not be used for new development.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With