Wednesday, March 28, 2012

PageMethod vs WebSerivce/ServiceMethod

I've seen people say that we shouldn't use PageMethods and should stick with using web services as is currently written, however, I've not seen a reason why. My situation right now is that I want to combine the HoverMenuExtender and DynamicPopulateExtender to display a preview of an item for my gridview. However, my site uses forms authentication, and if I try to pull the html (screen grab) from the page, I just get the forms login page. So I'm curious as to why I shouldn't use a page method which wouldn't have the authentication problem. We already have a webservice running, and I'd rather use that webservice, but since it seems like I can't - I'd rather use a page method then start another webservice.Surely someone has an opinionWink
Surely someone has an opinionWink
Performance would come to mind. A page method requires an (almost) complete run through the page life cycle. Only the render phase is scipt.
Hi,

a page method doesn't require a full run through the page lifecycle. For this reason it is the preferred alternative to a partial postback, where the page goes through all its lifecycle.

Also, in a partial postback, even if only the html for the controls to update is sent in the response, all the web controls are actually rendering their content (but they do it writing into a NullTextWriter).
PageMethod:
I and the IL code disagree. The ScriptModule Registers the PageServiceHandler which in turn sets a RenderMethodDelegate. Therefor, the page runs up unitl the Render method like it would normally. -> Less performance than a WebService call.

Thanks for the heads up on the UpdatePanel. Checked out the IL Code and there it is (the RenderMethodDelegate) in hte ScriptManager.
Hi,

apologies for the confusion I made in my last post, you're perfectly right.

However, my opinion is that the choice between a page method and a web service should be driven by the particular scenario (the data to expose, the need for the elaboration to access the controls on the page) and not by performance.

No comments:

Post a Comment