FREE Subscription to Dr. Dobb’s Digest: Same Great Content, New Digital Edition
Site Archive (Complete)
Windows/.NET
Email
Print
Reprint

add to:
Del.icio.us
Digg
Google
Furl
Slashdot
Y! MyWeb
Blink
March 13, 2007
AJAX and Asynchronous Pages

Dino Esposito
AJAX-style programming offers some real advantages in flexibility and better UI feedback, but Dino points out one downside to ASP.NET AJAX that can negatively affect scalability.

One of the biggest advantages of ASP.NET AJAX is the ability to call server-side methods from within the client browser using JavaScript. Instead of posting a form to get back a brand new version of the current page, you can now take control yourself of the operations and invoke a specific method defined on the same server as the application. Input parameters for the method, and any return values, are serialized back and forth. The ASP.NET AJAX infrastructure takes care of data transfer and serialization on both the client and the server. You can define the server API that the client can invoke either using a specialized ASP.NET Web service or using static methods defined on the page's code-behind class.

The method call is executed asynchronously with respect to the client. This fact has a few positive repercussions on the page.

First and foremost, the page is not frozen during the execution of the method. The user can continue his interaction with the page and type in new data or even command a second method call. Good feedback and progress screens can be displayed to the user. The feedback screen is not limited to static text and markup. You can use marquees as well as animated GIFs. Because the current page is not killed waiting for a brand new one to be downloaded, the background thread that animates the image is still alive and can continue doing its own job. When the remote method invocation is completed and results are ready to be processed on the client, a user-defined JavaScript callback is called to merge received data with the current page tree. It looks like a simple and effective model with no downsides. Is it really true? Let's find out.

It is essential to notice that an AJAX asynchronous call is asynchronous only with the respect to the client browser. As far as the ASP.NET runtime engine is concerned, it remains a synchronous call. Is this a problem? It can become a problem; and a big one indeed. Let's examine what happens internally when a server method is invoked through a wrapper Web service.

When you expose the client-callable server API, you create an ASMX Web service. The ASP.NET AJAX framework then creates a JavaScript proxy class for the service. Whenever you call a method on the proxy class, a request for the ASMX resource hits the Web server. In the end, the ASP.NET runtime receives a request for an ASMX resource. In the ASP.NET runtime, these requests can only be served synchronously. This means that the ASP.NET pooled thread in charge of the request can't do much more than waiting for the method to terminate. If the Web service method takes a while, the thread is blocked. When too many threads get blocked, you have a potential problem of scalability. An asynchronous HTTP handler for ASMX resources is not in ASP.NET 2.0. You can write your own, but it wouldn't be a picnic.

ASP.NET AJAX is not necessarily a friendly framework if you have strong scalability requirements and the need to invoke lengthy server methods. Solutions? The most obvious is avoiding the method call from the client. Make a postback, or even a partial postback, and mark the ASP.NET page as asynchronous. ASP.NET pages can be processed asynchronously on the server; ASP.NET Web services cannot.

TOP 5 ARTICLES
No Top Articles.
DR. DOBB'S CAREER CENTER
Looking for a new job? open | close
Search jobs on Dr. Dobb's TechCareers
Function:

Keyword(s):

State:  
  • Post Your Resume
  • Employers Area
  • News & Features
  • Blogs & Forums
  • Career Resources

    Browse By:
    Location | Employer | City
  • Most Recent Posts:



    MICROSITES
    FEATURED TOPIC

    ADDITIONAL TOPICS

    INFO-LINK



     




    Techweb
    Informationweek Business Technology Network
    InformationweekInformationweek 500Informationweek 500 ConferenceInformationweek AnalyticsInformationweek Events
    Informationweek MagazineGlobal CIOIWK Government ITbMightyByte and SwitchDark Reading
    Digital LibraryIntelligent EnterpriseInternet EvolutionNetwork ComputingPlug Into The CloudDr. DobbsContentinople
    space
    TechWeb Events Network
    InteropVoiceConWeb 2.0 ExpoWeb 2.0 SummitEnterprise 2.0Mobile Business ExpoNoJitter
    Black HatGTECEnergy CampCloud ConnectGov 2.0 ExpoGov 2.0 Summit
    space
    Light Reading Communications Network
    Light ReadingLight Reading AsiaUnstrungCable Digital NewsInternet EvolutionPyramid Research
    Heavy ReadingLight Reading LiveLight Reading InsiderEthrnet ExpoTelco TVTower Technology Summit
    space
    Financial Technology Network
    Advanced TradingBank Systems and TechnologyInsurance and TechnologyWall Street and TechnologyAccelerating WallstreetBST SummitBuyside Trading SummitIT Summit
    space
    Microsoft Technology Network
    MSDNTechNetTotal IT ProTotal Dev ProNET Total Dev Pro CommunitySQL Total Dev Pro Community
    space