Is the Web API more efficient than Web Methods to access data in a C#application?

Asked

Viewed 19 times

0

Today on the C# Dotnet you can access a C# function on your ASPX page by javascript, without needing Jquery. As long as the function is Static and dependent on system.web.service.webmethod on an ASPX page. Just put in it the ajax control scriptManager with the attribute pagemethods= true. The access is background without post on the page and very fast! But today the pages ASPX are being replaced by HTML both for architectures such as MVC and even to better separate the front end from the back end.

  1. This analysis is real?
  2. If it is better to use HTML, use Web API in the projects Dotnet are a correct solution to replace ASPX or there is a way to use ajax Webmethods in HTML pages?
  3. What’s faster and more robust to access my C#back-end? The Web API or Web Methods?
  4. Which is most used today?

Example of calling using System.Web.Services.Webmethods:

Javascript:

function salvaCliente(dados){

  PageMethods.saveCliente(dados, onSuccess, onError);

    function onSuccess(retorno) {

        if (retorno == "") {
            alert("Cliente salvo com sucesso!");
        }else{
            alert(retorno);
        }
    }

    function onError(retorno) {
        alert(retorno.message);
    }

C#

[System.Web.Services.WebMethod]
public static string saveCliente(string dados)
{
    string retorno = cliente.insert(dados);
    return(retorno);
}

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.