Books & ebooks about Microsoft tools, technologies, & research. Plus programming best practices. We hope you enjoy this post.
You might already know that Dino Esposito is an expert on Web technologies. If you do, you’ve probably been looking forward to his new book, which is now available: Microsoft ASP.NET and AJAX: Architecting Web Applications (Microsoft Press, 2009; ISBN: 9780735626218; 352 pages). In this post we’ll provide you with some excerpts from the book.
This is the book’s high-level structure:
And here is Dino’s overview of the book:
Introduction
This book is the Web counterpart to another recently released book I co-authored withAndrea Saltarello: Microsoft .NET: Architecting Applications for the Enterprise (MicrosoftPress, 2008). I wrote it, in part, in response to the many architectural questions—both smallquestions and big ones—that I was asked repeatedly while teaching ASP.NET, AJAX, andSilverlight classes.
Everybody in the industry is committed to AJAX. Everybody understands the impact of it.Everybody recognizes the enormous power that can be derived from its employment inreal-world solutions.
Very few, though, know exactly how to make it happen. There are so many variations to AJAXand so many implementations that even after you have found one that suits your needs, youare left wondering whether that is the best possible option.
The fact is that AJAX triggered a chain reaction in the world of the Web. AJAX represents achange of paradigm for Web applications. And, as the history of science proves, a paradigmshift has always had a deep impact, especially in scenarios that were previously stable andconsolidated.
I estimate that it will take about five years to absorb the word AJAX (and all of its background)into the new definition of the Web. And the clock started ticking about four years ago. Thetime at which we say “the Web” without feeling the need to specify whether it contains AJAXor not . . . well, that time is getting closer and closer. But it is not that time yet.
Tools and programming paradigms for AJAX, which were very blurry just a few years ago,are getting sharper every day. Whether we are talking about JavaScript libraries or suitesof server controls, I feel that pragmatic architectures can be identified. You find themthoroughly discussed in Chapter 3, “AJAX Architectures.”
Architecting a Web application today is mostly about deciding whether to prefer the richnessof the solution over the reach of the solution. Silverlight and ASP.NET AJAX are the twoplatforms to choose from as long as you remain in the Microsoft ecosystem. But the rich vs.reach dilemma is a general one and transcends platforms and vendors. A neat answer to thatdilemma puts you on the right track to developing your next-generation Web solution.
Who This Book Is For
I believe that this book is ideal reading for any professionals involved with the ASP.NETplatform and who are willing or needing to find a solution that delivers a modern and richuser experience.
Finally, here is a longish stretch of text from Chapter 3:
Chapter 3AJAX Architectures
Freedom is not worth having if it does not include the freedom to make mistakes.—Mahatma Gandhi
In the previous chapter, we examined strategies for getting AJAX easily and smoothly intoour ASP.NET applications. Partial rendering is definitely worth a try because it doesn’t requirea steep and long learning curve and has a limited, often low, impact on the existing code.Unfortunately, though, partial rendering doesn’t really capture the heart of the AJAXparadigm. A very similar metaphor to describe partial rendering in the context of AJAX isthe following. Partial rendering doesn’t teach you how to fish; rather, it opens up a new fishmarket nearby where you can order nearly all types of fish and pay for it. In the fish market,though, deliveries are not possible every day and the fish is not always the catch of the day.All things considered, if you want your seafood shopping to be easy and are ready to makesome compromises, this fish market is an excellent solution—just as partial rendering mightbe a good solution in the AJAX world.
What alternatives exist to partial rendering?
Pushing the focus to the server was ASP.NET’s remarkable contribution to the success ofthe Web platform. Before ASP.NET, Web professionals and software professionals were twodistinct categories of developers, with different skills. With ASP.NET, many C++ developersapproached the Web without needing to learn JavaScript and HTML in depth. AJAXmoves the focus back to the client, and the Web client platform is made of JavaScript andHTML. This means that at the other extreme of partial rendering you find a handcraftedcombination of JavaScript and HTML.
Frankly, a similar solution can hardly be employed in a large enterprise solution with hundredsof pages because such an approach is too risky, fragile, and error prone. An alternative thatcan really speed up development while remaining reliable and effective is to use specializedserver controls that offer AJAX functionalities out of the box. Many commercial frameworks doexactly this. Depending on the level of abstraction of the various frameworks, you might feellike you’re using a brand new component-based language on top of ASP.NET or just anenhanced version of ASP.NET.
Regardless of the level of abstraction, the underlying architecture remains the same.You essentially design the user interface using server controls that emit both JavaScript andHTML. The output of each server control is bound to some JavaScript event handlers that fireHTTP calls to the Web server as the user interacts with input elements. The server-siderecipients of HTTP calls might also take different shapes (for example, SOAP, JSON, orREST services), depending on the design principles and vision that inspired the frameworkyou’re using.
In this chapter, we’ll review the two main AJAX application architectures that have emergedas the most popular and effective. No recognized names exist (that I’m aware of) to indicatethese two architectural patterns. I’ll (kind of arbitrarily) refer to them as AJAX Service Layerand AJAX Server Pages.
The AJAX Service Layer Pattern
At the highest level of abstraction, Web applications are client/server applications thatrequire an Internet connection between the two layers. Before AJAX, this connection wasincorporated in the special client application—the browser. The browser opens theconnection, clears the user interface, and then updates the screen with the results of aserver operation.
With AJAX, the client code has the ability to bypass the browser and can handle connectionsitself. This enables the client to enter user interface updates without fully refreshing thedisplayed page—a great step forward toward usability and rich user experiences.To make the usability of Web applications grow as close as possible to that of desktopapplications, the overall software platform must fulfill two key requirements. As mentioned,one is a client-side infrastructure that can manage the Internet connection with the server.The other requirement is the availability of a public and known programming interface onthe server—the AJAX-specific service layer.
Architectural Overview
Any AJAX solution is made of two main layers that are neatly separated but communicating—the JavaScript and HTML presentation layer and a service layer that acts as a façade for HTTPendpoints. Figure 3-1 gives an overview of the architecture.
The presentation layer is hosted in the browser and communicates via HTTP with an ad hocfaçade made of URLs. Behind the URLs, you have server code at work. The server code canbe exposed in a number of ways determined by the programming API you choose—forexample, Windows Communication Foundation (WCF) services.
The data being exchanged between the presentation layer and the HTTP façade depends onthe client and server APIs and their capabilities. However, most of the time, albeit not alwaysand not necessarily, JSON is the serialization format of choice.
The communication between the HTTP façade and the rest of the system happens either locallyor over a protected network environment where only trusted callers are allowed.
HTTP Façade
As shown in Figure 3-1, the HTTP façade just reworks a more convenient API for thepresentation layer to call. The API is built on top of application services and workflows. TheHTTP façade just scripts these middle-tier components from the client.
The architectural relevance of the HTTP façade is that it decouples the middle tier froma very special presentation layer, such as an AJAX presentation layer. An AJAX presentationlayer is special essentially because it’s a partial trust Web client.
For security reasons, service technologies hosted on the Web server require special adjustmentsto enable JavaScript callers. In addition, it’s likely that some of the application services you havein the middle tier run critical procedures. Any piece of code bound to a URL in the HTTP façade,instead, is publicly exposed over the Internet. Not an ideal situation for a business-criticalservice. So decoupling application services from the AJAX presentation layer is a measure ofdesign but also a matter of security.
As an architect, you know that a business layer might sometimes include an outermost layerof code that is used to script the domain model and business components and services.The structure of this layer is inspired by the Service Layer pattern. In general, a service layerdefines an interface for the presentation layer to trigger predefined system actions. As thename suggests, the service layer is a sort of boundary that marks where the presentationlayer ends and the business logic begins. The service layer is designed to keep couplingbetween the presentation layer and business logic to a minimum, regardless of how thebusiness logic is organized within the business logic layer.
How does the HTTP façade relate to a service layer?
HTTP Façade and the Service Layer Pattern
A service layer doesn’t really perform any task directly. All that it does is orchestrate theset of business objects in the middle tier. The service layer has an intimate knowledgeof the business logic (including components, workflows, and services), and likewise itknows the domain model, if any, very well. The service layer is, therefore, part of thebusiness layer.
Ideally, the HTTP façade lives on top of the business layer and, subsequently, it liveson top of the service layer. Despite the word service in the name, a service layer is notnecessarily made of services such as WCF or Web services. The service layer also can be aplain collection of classes. This is not uncommon in classic ASP.NET applications, where thecode-behind class lives on the server and doesn’t need a Web or WCF interface to call intothe middle tier. A service-based service layer is more common when you have a smart clientand need a physical connection to the server to operate. In this case, a WCF service is thebest option.
In general, I suggest you opt for a WCF service only if you really need it. Note that havinga WCF service only to connect presentation and business components might be overkill insome simple cases. On the other hand, when the client is an AJAX platform, you do needan HTTP endpoint to start server-side operations. In the .NET Framework 3.5, a simpleWCF service is an excellent HTTP endpoint, but other options exist as well. The endpointexposed to the client can be made of the services in the service layer (if you have servicesthere), or it can be an additional layer of ad hoc AJAX services that just talk to the servicelayer or, more in general, to the business layer. (See Figure 3-2.)
The service layer (if you have one) is the layer invoked by the presentation layer. In the caseof an AJAX presentation layer, either the service layer is publicly exposed to the Internet( becoming itself the HTTP façade) or it’s shielded by a made-to-measure HTTP façade.
Let’s expand on the technologies available to build an HTTP façade.
Technologies for the HTTP Façade
The HTTP façade is the list of public URLs known to and managed by the AJAX presentationlayer. In an AJAX scenario, the presentation layer is made of only JavaScript code. All the logicyou can’t or don’t want to code in JavaScript must be referenced on the server.
Public HTTP endpoints are the only point of contact between AJAX clients and serverapplications. In the .NET Framework 3.5, you can write endpoints callable by AJAX clientsusing a number of technologies.
To start off, an AJAX-callable endpoint can be an .asmx ASP.NET Web service. If this is yourchoice, you need to configure the host application so that its hosted Web services can acceptJSON calls in addition to, or instead of, SOAP calls.
PingBack from http://microsoft-sharepoint.simplynetdev.com/new-book-microsoft-aspnet-and-ajax-architecting-web-applications/
…of the U.S. Billboard Hot Soul Singles for The O’Jays in 1975 . And Sugar Minott recorded “Give the
Excellent, Excellent, Excellent... This is the way which I can describe the book.