Difference between two ancient web programming technologies CGI and ISAPI

Source: Internet
Author: User

// This document is taken from Internet

 

I. Introduction
Both ISAPI and CGI are common gateway interfaces, which are used to implement information interaction between the WWW server and the client.

With the explosive development of WWW and its increasing popularity, people's eyes have been attracted by its business opportunities. There are several ways to seek economic benefits on WWW:

Fees are charged for advertising activities such as advertising;

The inbound viewer is charged for the renewal fee;

Sell goods and services directly online.
Currently, most websites provide information by connecting users to the WWW server through a client browser (such as Netscape or Explorer), and then clicking the hyperlink to browse the relevant homepage. In this process, the server transmits information to the client in a single direction. As the service requirements continue to expand, the static homepage that simply transmits information in a single direction cannot meet the requirements. Both the service provider and the customer want the browser server to send the information to the user, and the user side can also send the information to the server side to realize the interaction between the server and the customer. Typical applications include user registration forms, user message boards, and user retrieval of Server databases through www.

To implement a service system that can interact with users, you need to add two items: Interactive homepage and user input information processing.Program. The interactive Homepage contains an editing box for the input information. Select a Home Page such as the menu button for the user to enter the information. The information entered by the user is processed by the user information processing program. There are multiple ways to implement the program. The program can be placed on the server or the client. The former is CGI or ISAPI, and the latter is javaapplet. This article only discusses the former, describes the advantages of ISAPI, and provides examples for its implementation.

Ii. web interaction environment implementation
2.1 interactive Homepage

To implement a web interaction environment, the user must be able to input information on the home page that he browsed. This is an interactive home page. Generally, you can enter an editing box, select a wireless button, or select a drop-down menu in the form of user input information. Therefore, the interactive homepage must also have these input elements. The following is an example of a simple interactive homepage:

Interactive homepage HTML source file: isapi1.htm

「 HTML 」
"Title" test "/Title 」
「 Head 」
Isapitest
「/Head 」
"Body 」
「 Formaction = 」/gjy/isapi1/debug/isapi1.dll? Registeruser "method = Post 」
Inputyourregisterinfomation: "Br 」
Name: "inputtype =" text "name =" first "" Br 」
Address: "inputtype =" text "name =" Middle "Br 」
Email: "inputtype =" text "name =" last "Br" "P 」
"Inputtype =" Submit "」
"Inputtype =" reset "/P 」
「/Form 」
「/Body 」
「/Html 」

Open the file in the Explorer browser and you can see the following results (the content has been entered in the edit box ):

2.2.

As you can see from the above homepage production description, the production of an interactive homepage is very simple, but to truly achieve interaction with users, you must also participate in the application. This program can belong to multiple styles, such as CGI, javaapplet, and ISAPI. In the preceding homepage file, there is one:

「 Formaction = 」/gjy/isapi1/debug/isapi1.dll? Registeruser "method = Post 」

The Program (isapi1.dll) that processes the input information of this homepage is specified here. This is the dynamic Connection Library of the ISAPI application. The same is true for CGI applications.

In general, the function of this program is to transmit user input information to the server application.

CGI is an effective way to implement the above functions that everyone is familiar with. It may also be the most popular one, ISAPI is a unique network application interface standard that Microsoft has similar CGI functions. Compared with CGI, ISAPI has many excellent features. Next we will briefly introduce the performance differences between CGI and ISAPI and between them.

Iii. cgi principles and Performance
3.1cgi Concept

CGI is the universal Gateway Interface (commongatewayinterface), which is a WWW server.

Standard Interface for external service of the host. Generally, a CGI interface is used to transmit information between Hypertext files and server host applications.

3.2cgi Programming Language

In fact, any program language, as long as it can use the CGI interface on the server host to write an application, can be called the CGI program language. Currently, the most popular CGI programming languages are C, Shell, Perl, and VisualBasic. Many other languages are also used, such as TCL, Fortran, and applescript.

3.3cgi Program Execution

CGI programs are generally executable programs. The compiled CGI program is usually stored in a directory. The specific storage location varies with the operating system. For example, the UNIX system is stored in the cgi-bin subdirectory while the Windows operating system (note that NT4.0 is not included here) use WebStar or website as the WWW server, and place CGI programs under CGI-win. CGI programs generally run in two ways: 1 is called directly through a URL, for example, "http: // 202.114.2.182/cgi-Win/cgi.exe ", you can directly write the preceding description in the URL bar of the browser to call the program. The other method is also the main method, which is called through the form bar on the interactive homepage, generally, after entering a home page of input information, you can press the OK button to start the CGI program. The previous interactive home page is a typical example of calling CGI.

3.4cgi main Workflow

The main process of CGI is: 1. A user requests to activate a CGI application; 2. the CGI application extracts user input information from the interactive homepage. 3. transmit user input information to server host applications (such as database queries); 4. return the server processing result to the user through an HTML file; 5. the CGI process ends.

3.5cgi Performance Evaluation

CGI provides excellent cross-platform performance and can be implemented on almost any operating system, such as DOS, windows, UNIX, OS/2, and Macintosh. CGI implementationProgramming LanguageThere are also many options. CGI applications are generally an independent executable program, which is different from the WWW server. Generally, a CGI program can only process one user request. In this way, every user request will activate a CGI process. When the number of user requests is very large, a large amount of system resources such as memory and CPU time will be occupied, resulting in low efficiency.

Iv. ISAPI principles and Performance
4.1isapi Concept

ISAPI is internetserverapplicationprograminterface. It is a set of API interfaces provided by Microsoft for Internet services. It can implement all the functions provided by CGI and is extended on this basis, for example, the filter application interface is provided.

4.2isapi Programming Language

Since the development of ISAPI applications requires a set of Microsoft APIs, the languages that can be used to develop ISAPI applications are not as many as CGI. It mainly supports visual C ++ 4.1 and later versions, and also supports visual basic5.0 and BorlandC ++ 5.0.

4.3isapi Principle

The operation principle of ISAPI is basically the same as that of CGI. ISAPI obtains user input information through the interactive homepage and submits the information to the server background for processing. However, the two have a major role in the implementation mechanism. The major difference between ISAPI and CGI is that, unlike CGI, Applications created under ISAPI exist in the form of dynamic connection libraries, while CGI applications are generally executable programs.

4.4isapi Program Execution

The workflow of an ISAPI application is somewhat different from that of CGI. The ISAPI application dll can be activated by a user request like a CGI program, and can be pre-activated by the system to monitor user input. for user-activated DLL, after processing a user request, it does not disappear immediately. Instead, it continues to reside in the memory and waits for other user input to be processed. After a period of time, no user input remains.

 

4.5isapi Performance Evaluation

An isapi dll can be stored in the memory after being activated by a user request, waiting for another user request. You can also set multiple user request processing functions in a DLL. In addition, the isapi dll application is in the same process as the WWW server, and the efficiency is significantly higher than that of CGI.

However, the ISAPI platform has poor compatibility. Currently, it can only be used on Microsoft's Windows 95 and NT operating systems. The server platform is also limited to IIS (internetinformationserver), mspersonalwebserver, and peerwebserver on ntworkstation.

5. Implementation of ISAPI
The platform that supports ISAPI development is only a combination of several Microsoft platforms (such as nt + IIS, Win95 + mspersonalwebserver ). Therefore, isapis can only be developed on these platforms. As described earlier in the development language, we recommend visual c ++ 4.2 for you. Its wizard provides functions dedicated to creating isapis.

The following is a simple example. The function is to display the user's input from the browser to the user. The function is simple, but it has all the typical ISAPI processes. The source code is as follows (most ofCode):

1. Main Program:
// Isapi1.cpp-implementationfileforyourinternetserver
# Include "stdafx. H"
# Include "isapi1.h"
//////////////////////////////////////// ///////////////////////////////
// Theoneandonlycwinappobject
// Note: youmayremovethisobjectifyoualteryourprojecttono
// Longerusemfcinadll.
Cwinapptheapp;
//////////////////////////////////////// ///////////////////////////////
// Command-parsingmap
Begin_parse_map (cisapi1extension, chttpserver)
/************ Mycodesbeginhere ***********/
On_parse_command (registeruser,
Cisapi1extension, its_pstrits_pstrits_pstr)
On_parse_command_params ("firstmiddlelast ")
/************* Mycodesendhere ***********/
End_parse_map (cisapi1extension)

//////////////////////////////////////// ///////////////////////////////
// Theoneandonlycisapi1extensionobject

Cisapi1extensiontheextension;

//////////////////////////////////////// ///////////////////////////////
// Cisapi1extensionimplementation

Cisapi1extension: cisapi1extension ()
{
}

Cisapi1extension ::~ Cisapi1extension ()
{
}

Boolcisapi1extension: getextensionversion
(Hse_version_info * pver)
{
// Calldefaultimplementationforinitialization
Chttpserver: getextensionversion (pver );

// Loaddescriptionstring
Tcharsz [hse_max_ext_dll_name_len + 1];
Isapiverify (: loadstring (afxgetresourcehandle (),
Ids_server, SZ, hse_max_ext_dll_name_len ));
_ Tcscpy (pver-> lpszextensiondesc, SZ );
Returntrue;
}

///////////////////////////////////// /// //
// cisapi1extensioncommandhandlers
/******** mycodebeginshere ***********/
voidcisapi1extension:: registeruser
(chttpservercontext * pctxt, lpctstr
pstrfirst, lpctstrpstrmiddle, and lpctstrpstrlast)
{< br> // doprocessinghere!
* pctxt <_ T ("yournameis:");
* pctxt <_ T (pstrfirst );
* pctxt <_ T ("\ n");
* pctxt <_ T ("youraddressis :");
* pctxt <_ T (pstrmiddle);
* pctxt <_ T ("\ n ");
* pctxt <_ T ("youre_mailis:");
* pctxt <_ T (pstrlast );
}< br>/********** mycodesendhere **********/
// donoteditthefollowinglines,
whichareneededbyclasswizard.
# if0
frequency (cisapi1extension, chttpserver)
// {afx_msg_map (cisapi1extension)
//}} afx_msg_map
end_message_map ()
# endif // 0
2. master header file
// isapi1.h-headerfileforyourinternetserver
// isapi1extension

# Include "resource. H"
Classcisapi1extension: publicchttpserver
{
Public:
Cisapi1extension ();
~ Cisapi1extension ();

// Overrides
// Classwizardgeneratedvirtualfunctionoverrides
// Note-theclasswizardwilladdandremovememberfunctionshere.
// Donoteditwhatyouseeintheseblocksofgeneratedcode!
// {Afx_virtual (cisapi1extension)
Public:
Virtualboolgetextensionversion (hse_version_info * pver );
//} Afx_virtual
// Todo: addhandlersforyourcommandshere.
/*********** Mycodedbeginhere (function declaration )*********/
Voidregisteruser (chttpservercontext * pctxt,
Lpctstrpstrfirst, lpctstr
Pstrmiddle, lpctstrpstrlast );
/********* Mycodesendhere
Declare_parse_map ()

// {Afx_msg (cisapi1extension)
//} Afx_msg
};
3. Dynamic Connection Library definition file
/*************************************/
/* Isapi1.def */
/*************************************/
; Isapi1.def: declaresthemoduleparametersforthedll.
Library "isapi1"
Exports
Httpextensionproc
Getextensionversion

In the above program, a chttpserver class cisapi1extension is defined, which is the main class of the program and implements the function of interacting with users. The on_parse_command Section implements function ing. The above program defines a member function registeruser In the DLL. Its function is to send the information entered in the editing box back to the user. For more information, see the vc4.2 help document.

 

Compile the above file into a DLL and put it in the scripts directory specified by the WWW server on the server host. The logical name of the directory should be consistent with that on the interactive homepage. After the settings are complete, connect to the server through a browser, browse the home page, and enter the information in the edit box.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.