Chapter 1. Service-Oriented AJAX Fundamentals

After completing this chapter, you will

  • Understand the architectural principles of service-based AJAX development.

  • Understand the role of the ScriptManager control and the Microsoft AJAX Library in the client-side JavaScript runtime.

  • Be able to use basic techniques for AJAX programming with ASP.NET AJAX 3.5.

  • Be able to implement simple services for AJAX using Windows Communication Foundation (WCF).

  • Be able to call simple Web services from an AJAX application.

Service-Based AJAX: Architecture Overview

Programming a service-based AJAX application requires a new approach to Web development and a fundamental change in how you conceive and build applications. In a traditional ASP.NET application, you create page-based Web Forms applications. I’ll call this "classic ASP.NET." The classic ASP.NET Web Forms architecture is monolithic: in classic ASP.NET, you create functionality for a form-based user interface. With service-oriented AJAX applications, your functionality is no longer tied to a page or Web form. It is instead based on Web services that can be called from any page or application. Even the JavaScript components that form the AJAX application aren’t tied to a page; they exist as components that can be used in many pages and applications and loaded as they are needed.

Note

Note

A service-based AJAX application is implemented with JavaScript components programmed against Web services. Service-based AJAX development applies the principles of service orientation to Web application development.

While you have many architecture choices for AJAX applications, the service-based architectural style fits well and offers the greatest amount of flexibility, reusability, and extensibility. With advances in Web service technologies through Windows Communication Foundation (WCF) and JavaScript support for network services in the ASP.NET AJAX Extensions, Microsoft has created a rich platform for developing not just a service-oriented architecture but also service-based AJAX applications.

With a service-based application, you have a clean separation of the API layer and the user interface. To create this separation using the Microsoft .NET 3.5 Framework, you first write an API by using WCF Web service technologies, and then you write the AJAX user interface with browser-based client technologies. The client application is built on the ASP.NET AJAX Extensions by using JavaScript and dynamic HTML. The service-based AJAX application is a client-side runtime that renders the user interface and calls back-end services, with a reusable, tested, and secure service-oriented back end exposed through WCF endpoints. This architecture is a good fit with Microsoft servers such as Microsoft Office SharePoint Server and third-party enterprise servers such as NewsGator Enterprise Server. Seldom do applications in the enterprise run as isolated applications; because the AJAX architecture is service based, it is also an ideal choice for integration with third-party applications.

Three goals of service-based AJAX are to decouple the user interface from the back end, to create reusable services, and to create reusable AJAX components. Because of this decoupling, the application can evolve as a user interacts with it. Additional AJAX components can be loaded as they are needed, and views can navigate through data sets as the user browses data. What used to happen in a classic ASP.NET application that spanned multiple pages can happen in one client runtime that is dynamically loaded and destroyed as necessary during the page execution. And because all the components are programmed against Web services, you have a lot of opportunities for reuse. This is a great shift from traditional server-side ASP.NET development. Unlike the monolithic page-based programming model, service-based AJAX development is divided into server-based API programming and client-based component development that consumes the service-oriented API. Figure 1-1 illustrates this architecture and demonstrates the service-based AJAX architecture pattern.

The service-based AJAX architecture pattern, with JavaScript clients talking to WCF service endpoints.

Figure 1-1. The service-based AJAX architecture pattern, with JavaScript clients talking to WCF service endpoints.

With this architecture, it is easy to swap out the AJAX interface or add additional client applications—including Microsoft Silverlight, Adobe Flash, and Microsoft Windows Presentation Foundation applications or even Macintosh clients—all connected through Web services. It is also simple to use both services and client components in multiple contexts throughout your application. To show you how the basic architecture fits together, I’ll first describe the ASP.NET AJAX client runtime. I’ll then illustrate a service-based back-end system using Web services in WCF.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset