To learn more about author Sanjaya Hettihewa, please visit the author's homepage.
ISAPI (Internet Server Applications Programming Interface) is a high-performance programming interface for developing Web-server applications. ISAPI applications can be executed on any ISAPI- compatible Web server, such as Internet Information Server or Purveyor. Unlike regular CGI applications that are compiled into EXE files, ISAPI applications are compiled into DLL files.
Although CGI applications can be used to develop interactive Web applications (as demonstrated in Chapter 10, "Developing CGI Applications"), CGI by itself does not provide a very scalable development environment. CGI applications are resource intensive because a new process must be created for each CGI request. This involves a great deal of overhead and adversely affects the scalability of CGI applications. ISAPI applications are free from the process-creation and -teardown overhead associated with CGI applications.
ISAPI applications can be developed using the C++ programming language. The purpose of this chapter is not to demonstrate how various capabilities of C++ can be used to develop applications. Instead, you will be shown how to use Microsoft Visual C++ 4.2 to develop an ISAPI application that displays the string Hello World! For additional information about C++ application development, check out Teach Yourself ANSI C++ in 21 Days, Premier Edition and Visual C++ 4 Unleashed, both by Sams Publishing. You can extend the application presented in this chapter according to your needs.
Launch Microsoft Developer Studio to begin creating the Hello World! ISAPI application.
After you launch Microsoft Developer Studio, select File|New from the menu bar. You
are presented with the New dialog box shown in Figure 11.1. Use this dialog box to
select to create a new project workspace.
Figure 11.1. The New dialog box.
Use the New Project Workspace dialog box (shown in Figure 11.2) to select what type
of application you want to create. Use the scroll-down list to select to create an
ISAPI extension using the ISAPI Extension wizard (as shown in Figure 11.2). Name
the project HelloWorld and click the Create button.
Figure 11.2. Select to create an ISAPI
extension.
Use the ISAPI Extension Wizard dialog box (shown in Figure 11.3) to specify characteristics
of your ISAPI application. Select the Generate a Server Extension object check box
(as shown in Figure 11.3). By selecting to generate a server extension object, you
can compile your program into an ISAPI DLL that users browsing your Web site can
execute. If you select to generate a filter object, your program can interact with
any Web-server transaction by manipulating the headers and URL information of HTTP
requests. The ISAPI application you are creating uses Microsoft Foundation Classes
(MFC) functions. You may either use the MFC functions dynamically or export required
functions to your application. Select to use the MFC library as a shared DLL by enabling
the As a shared DLL radio button. This allows you to use MFC functions that are already
loaded in memory on your system. Click the Finish button to proceed.
Figure 11.3. The ISAPI Extension wizard.
The New Project Information dialog box shown in Figure 11.4 displays information
about the ISAPI application you are about to create. Make a note of the location
of the install directory. The ISAPI DLL file is created inside this install directory.
Acknowledge the dialog box in Figure 11.4 to begin editing the Hello World! application.
Figure 11.4. The New Project Information
dialog box.
Locate the Project Workspace window and select the HelloWorld classes folder. Inside
the HelloWorld classes folder, locate the CHelloWorldExtension class and select the
default() function as shown in Figure 11.5. Double click the default() function to
edit it. The C++ code in the default() function is executed when the ISAPI application
is executed by a user.
Edit the default function shown in Figure 11.6. See Listing 11.1 for the default
contents of the default() function.
Figure 11.5. The Project Workspace window.
Figure 11.6. Edit the default()
function of the CHelloWorld Extension class.
void CHelloWorldExtension::Default(CHttpServerContext* pCtxt) { StartContent(pCtxt); WriteTitle(pCtxt); *pCtxt << T("This default message was produced by the Internet"); *pCtxt << T(" Server DLL Wizard. Edit your CHelloWorldExtension::Default()"); *pCtxt << T(" implementation to change it.\r\n"); EndContent(pCtxt); } Replace the contents of the default() function with the text in Listing 11.2.
void CHelloWorldExtension::Default(CHttpServerContext* pCtxt) { StartContent(pCtxt); WriteTitle(pCtxt); *pCtxt << T("<H1>Hello World!</H1>.\r\n"); EndContent(pCtxt); }
By default, Microsoft Visual C++ creates Win32 Debug applications. Although Win32
Debug applications are ideal for debugging, they are not as efficient as Win32 Release
applications. Use the pull-down menu shown in Figure 11.7 to create a Win32 Release
application. You can now select Build|Build HelloWorld.dll from the Microsoft Visual
C++ menu bar to build your ISAPI application.
Figure 11.7. Select to create a Win32
Release application.
Microsoft Visual C++ creates the Hello World! application in the Release subdirectory
of the Hello World! project directory as shown in Figure 11.8. Locate HelloWorld.dll
and copy it to the CGI directory of your Web server.
Use a Web browser to execute the Hello World! application as shown in Figure 11.9.
You are presented with the string Hello World! Your Web server should support ISAPI
for the Hello World! application to function properly.
Figure 11.8. HelloWorld.dll is created
in the Release subdirectory.
Figure 11.9. The ISAPI Hello World! application.
ISAPI is a powerful and scalable interface for developing CGI applications. Use ISAPI to develop CGI applications for Internet Information Server and other Web servers that support ISAPI to create powerful and scalable server-side Web applications.
© Copyright, Macmillan Computer Publishing. All rights reserved.