ASP.NET page methods vs web service
Asked Answered
K

2

14

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?

Katheryn answered 7/10, 2009 at 12:51 Comment(0)
S
19

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).

Safe answered 7/10, 2009 at 12:53 Comment(3)
hey @Russ same article again!Uri
@Uri - I wasn't expecting it to come up again so soon!Safe
@RussCam a follow-up question, Are PageMethods Async, or can they be made Async? I have hit a wall where one PageMethods call (that takes about 4 secondsto return) blocks and prevents other timer-based Page method calls from running as expected.Pinkard
J
0

Here is a good resource for you :

http://tugberkugurlu.com/archive/asp-net-web-forms---calling-web-service-page-methods-using-jquery

This blog post will walk you through.

Jamieson answered 20/10, 2011 at 7:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.