Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET page methods vs web service

I am building a dynamic partial load asp.net page, I would like to use jQuery to call page methods or web service to retrieve the content HTML.

page methods or web service, performance wise, which way is better?

If I call page method, on the server side, does the page go through full lifecycle?

Is there any good resources help me to better understand page method?

like image 273
nandin Avatar asked Oct 07 '09 12:10

nandin


People also ask

What is Web service and Web methods?

A web service is an exposed end point that is normally used as an API, or in other words its end user is typically another application rather than a user interface. A web method is a particular method that is exposed over a web service.

How is a web service different from an ASPX page?

ASPX pages are limited in the kinds of requests they can receive. They are strictly HTTP whereas a WCF service can have multiple endpoints to service a variety of protocols (HTTP, TCP, etc). WCF Services are more concretely defined due to ServiceContracts.

What are webmethods in asp net?

The WebMethod attribute is added to each method we want to expose as a Web Service. ASP.NET makes it possible to map traditional methods to Web Service operations through the System. Web. Services. WebMethod attribute and it supports a number of properties that control the behavior of the methods.

What is Web service in asp net?

Web services are components on a Web server that a client application can call by making HTTP requests across the Web. ASP.NET enables you to create custom Web services or to use built-in application services, and to call these services from any client application.


1 Answers

You can call PageMethods and Web Services without needing a ScriptManager control (which generates the JavaScript proxy objects that allow you to use familiar syntax to call web services and page methods).

Article on using jQuery to directly call ASP.NET AJAX page methods

Article on using jQuery to Consume ASP.NET JSON Web Services

Here's an MSDN article from 2007 on Web Services and Page Methods. Looking briefly through it, it seems to still be relevant to how they work / what you need to do to get them to work today.

Performance wise:

You might expect page methods to offer better performance than Web services. After all, to resolve Web service calls, the ASP.NET runtime has to parse SOAP packets. This, however, isn't exactly true. ASP.NET AJAX installs a tailor-made HTTP handler (see Figure 3) that intercepts all ASMX requests. Requests with a /js suffix are processed differently, working directly with the JSON payload and Web service method. As a result, no SOAP is involved whatsoever and the body of the request simply contains the JSON stream of input arguments. For non-AJAX requests, the new HTTP handler just delegates the call back to the original ASP.NET handler that understands SOAP.

In response to the Page Lifecycle, Page Methods do not go through the server-side Page LifeCycle (there is also a client-side Page Lifecycle too).

like image 177
Russ Cam Avatar answered Oct 02 '22 17:10

Russ Cam