Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Microsoft Visual C++ .NET Professional Projects - Premier Press

.pdf
Скачиваний:
180
Добавлен:
24.05.2014
Размер:
26 Мб
Скачать

630 Project 5 CREATING A COM COMPONENT USING ATL

Copy the HTML and ASP files into a folder. You need to create a virtual directory for this folder. To do so:

1. From the Programs menu, select Administrative Tools and run the Internet Services Manager (ISM).

2. Expand the tree view on the left side of the ISM. Right-click on the Default Web Site, select New, and select Virtual Directory, as shown in

 

 

Y

Figure 19-15. This starts the Virtual Directory Creation Wizard.

 

L

 

F

 

M

 

A

 

E

 

T

 

 

FIGURE 19-15 The Virtual Directory Creation Wizard

3.Click on Next, and on the resulting page, enter “test” as the alias for the virtual directory.

4.Click on Next, and select the folder in which you have copied the two files.

5.Click on Next, and on the resulting page, enter “test” as the alias for the site.

6.Click on Next to navigate to the Web Content Directory page. Here, enter the path of the folder where you have copied the two files, and then click Next to open the Access Permissions page, shown in Figure 19-16.

Team-Fly®

IMPLEMENTING COM USING ATL

Chapter 19

631

 

 

 

 

FIGURE 19-16 The Access Permissions page

7.Retain the default values. Click Next and then click Finish.

8.Run Internet Explorer. Connect to the virtual directory you have created using the URL http://localhost/test. Enter the credit card number and credit card type and verify the functioning of the component.

Summary

In this chapter, you created a credit card validation component using ATL. You saw that the ATL Project Wizard and attributes simplify the process of creating COM components. You also learned how to use the credit card component from both Windows applications, built using Visual Basic, and an ASP page.

This page intentionally left blank

PARTVIIProfessional

Project – 6

This page intentionally left blank

Project 6

Creating an ATL

Server

Application

Project 6 Overview

In this project, you’ll create a Guest Book application using the new ATL

Server library that is a part of Visual C++.NET. The ATL Server library is useful for creating high-performance Web applications using your knowledge of the C++ language and ATL. It simplifies programming features required by

Web applications like session management and database access.

The Guest Book application accepts user data and stores it in an XML file. This application allows a visitor to a Web site to leave his or her comments and e-mail address, thereby acting as a tool for accepting feedback from a site’s visitors.

The following are the concepts that I’ll use to build the Guest Book application:

ATL Server library

ATL library

XML Document Object Model

Error and exception handling

The ATL Server library is used to build the basic framework of the application. ATL is used to provide data handling, and XML DOM manipulation support. XSL is used to render XML data.

Chapter 20

Introduction to ATL Server

Web sites initially began as collections of static Web pages that were simple HTML pages. The static nature of the pages couldn’t address many needs and also couldn’t hold the customers’ attention for long. Therefore, the need arose

for interactivity in these pages. To add interactivity, CGI applications were designed. Using CGI applications, you could retrieve content from a form in a Web page and process it as required (for instance, store it in a database). But as the Web evolved, maintaining static Web pages created using HTML became tedious. Thus entered dynamic Web pages. The unique feature of dynamic Web pages was that the content could be brought in from any external source, such as a database. Initially, developers used CGI scripts and applications to create dynamic Web pages. However, all that changed once Microsoft introduced ASP, which allowed a Web developer to combine both HTML and scripting. ASP gained popularity predominantly because sites created using ASP not only were dynamic and interactive but also very easily maintainable. Besides ASP, other technologies, such as JSP and PHP, are also available for developers to develop Web applications targeted at various platforms.

Developers now have available a pool of technologies that can be used to develop Web applications. Which one best suits their requirements? Developer preference largely depends on the platform they are developing for and the ease of use of the technology. One other factor is the performance expected from the Web application. Technologies based on languages that are compiled, such as CGI applications developed using C or C++, give a better performance compared to those based on scripting languages, such as ASP and CGI scripts. Conversely, Web sites that use scripting-based technologies are more easily maintained.

Compiled technologies, such as CGI, have been around a long time and are used widely on servers based on operating systems such as Unix. However, on the Microsoft Windows platform, the process overhead associated with each CGI call makes CGI applications nonscalable. So, to provide similar support, Microsoft introduced Internet Server Application Programming (ISAPI) applications. ISAPI is an API that can be used to extend the functionality of the Web server (primarily IIS) and create high-performance Web applications.

INTRODUCTION TO ATL SERVER

Chapter 20

639

 

 

 

 

NOTE

You can create DLLs, called as ISAPI Extension DLLs, that contain the functionality desired of a Web application. ISAPI Extensions are of two types: ISAPI filters and ISAPI applications. ISAPI filters process all incoming client requests but are not explicitly invoked by the client. ISAPI applications are used to provide the same functionality as CGI applications. Just as you invoke a CGI application using an URL, you invoke an ISAPI application using an URL, even though the architectures of ISAPI and CGI vary. ISAPI applications provide dramatic performance improvements compared to CGI.

However, developing ISAPI applications using Visual C++ is difficult for building anything but very simple sites. Microsoft did try to make the task of creating ISAPI applications easier by adding an MFC-based wizard for ISAPI extensions, but it didn’t include built-in support for database access and standard Web features such as session management and cookies.

To overcome the stated drawbacks of ISAPI applications, Microsoft has introduced ATL Server. In this chapter, you will learn about ATL Server and how it addresses the issues previously discussed.

What Is ATL Server?

ATL Server is a library of C++ classes that simplifies the development of Web applications and Web services through compiled code. ATL Server is based on the ATL library that was originally designed to create lightweight COM components.

The main components in the ATL Server architecture are the Web server (IIS), an ISAPI extension DLL, one or more Web application DLLs, and Server Response Files (SRFs). Figure 20-1 depicts the ATL Server architecture.

The following list describes the role of each of these components in processing a client request:

The ISAPI Extension DLL. This DLL contains the default functionality for handling client requests, which is passed on by the Web server and will not be changed.