Mega Code Archive

 
Categories / Delphi / LAN Web TCP
 

From CGIWin9x to ISAPIW2K

Title: From CGI/Win9x to ISAPI/W2K Question: Migrate from CGI/Win9x to ISAPI/W2K Answer: INTRODUCTION First and foremost to excuse me by my extended absence, that fundamentally was had to my work and to a series of projects that I carry forward. Also to thank to the creators of this site by permitting so many persons to share their knowledge and experiences and by the premium granted to my person, the book is excellent. More information 'Delphi in a Nutshell' My intention here it is not to give a detail of each topic but a short guide of the steps that they could be followed and liaisons to sites for more information . THE BEGINNING As all history has a beginning and this can be summarized in the following way. In my company are distributed about all the country and all we communicate ourselves through a corporative Intranet. In one of the regional smallest emerged the need of implementing a system of control of transactions and daily sale operations of services, called from now on System X (the name does not has much relevancy), such is that of experimental way was put to work a system based on Windows 9x + Personal WebServer as "Web Server", the development of groups of applications CGI and a data base in Interbase 6.0. The system was evaluated and valued its real need for all our regional is that is decided to implement this service to all our country. The System X operating under a platform little stable as it is Windows 9x. and the use of CGIs for a reduced group of 40 concurrent users was not presenting too problem, as will be able to imagine alone were existing certain collisions in given moments by the use of the CGI and certain overcharge to the "web server". In this way accomplishing an analysis of the imminent migration to an environment where the quantity of concurrent users is approximately 400 and where obviously is required a real serving, is that is decided a migration of all the System X on Windows 2000 Server and to move all the code CGI and to convert it to ISAPI /DLL. THE OPERATIVE SYSTEM The migration of the Operative System do not present overdone complication, so alone to read some documentation and to work carefully in the installation. The development equipment go toward Professional W2K what more cost was let the usage of Win9x. Once taken confidence with the new operative system, was begun installing Delphi and other development tools in the mentioned platform, not without problems something funny as forgetting a patch by over there or the update this way . The migration of Interbase also is I accomplished it to Windows 2000 ++Server under a different server, providing future applications that certainly will exist. The migration of the users (programmers) of Win9x to W2K can be something traumatic if is not this preparation and if it has not been read the documentation carefully, especially in the topics of drivers or controlling of devices. Also it is made me important to mention that should not to rely totally on the minimal requirements outlined by Microsoft, I assure to /you that will require a better equipment. More Information http://www.microsoft.com/windows2000/guide/server/sysreq/default.asp THE WEB SERVER Even though the Web Server as application is integrated to the operative system in Windows 98 as well as in W2K is necessary to accomplish some observations separately. Personal WebServer PWS is a minimal configuration of Internet Information Server (++IIS) can be said that its purposes are radically different. On the one hand PWS it thought for a household user that wishes to put a small web page personal without too complications and obviously without too load and petition requirements. For an environment as the one which is I explained the configuration were found perfect though not free of mistakes and inconvenient. Additionally IIS 5.0 very strong and more reliable, not with this say that it does not has alone mistakes that it can be considered a platform more stable than ++PWS. The development on anyone of these serving two requires the comprehension of its operation and of the platform that supports it. In Windows 98 can be said that PWS is executed as a unsolicited process, that is to say when installs it is executed each time begins your computer. On the other hand in W2K, IIS it is executed as a service and is executed before to login to the system. In both it should be to change this behaviours by defect and to convert it to a requested manual process to which could be attached other, that it will be our ISAPI/DLL in debugging. This is indispensable alone and alone if is wished to accomplish the debug. If we have the ready and debugged DLL to be executed would not have to change the behaviour by defect of the web server. Some persons prefer to use the OmmiHttpd for the debug and after use IIS, it can be recommendable. More information http://community.borland.com/article/0,1410,20901,00.html http://www.fulgan.com/delphi/IIS.asp http://www.omnicron.ab.ca THE CODE SOURCE The benefits, the simplicity and comfort that offers PWS on Windows98 cause that are taken some bad habits in the programming of web applications. Here I present a code fragment, with bad programming habits of course . Code fragment of a WebAction Used to validate he number of a CI ( identification document) procedure TdmWebGet.dmWebGetwaccRec_EmpAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean); begin try if Not srhEmp.Prepared Then srhEmp.Prepared:=True; srhEmp.ParamByName ('pCI').AsString := Request.QueryFields.Values['pCI']; srhEmp.Open; {..... ..... ..... } except Response.SendRedirect ('/forms/error.htm'); end; end; The CGI has the particularity of executing the request and not to consume any type of additional resource (purportedly) after that ends the petition, this means that releases and closes any connection opened before be closed. As can be observed by comfort is let the task of connecting and opening the data base and the Transaction of control to the own CGI upon putting the property Activate always in TRUE and to compile it such which. This operates correctly but to move this code to an ISAPI implies to think of other form. Upon purifying a ISAPI/DLL it should be to care about executing the web server manner requested manual process if not believes me prove and side the genial falls that it can suffer Delphi when is attempted to accede to not freed resources or in use. Upon using a web server as manual process we will have the possibility of replacing the used DLL, of the contrary the only one form of replacing or erasing an ISAPI/DLL is to restart the equipment. The need of modifying the code is seen surpassed with the following code fragment. procedure TdmWebGet.dmWebGetwaccRec_EmpAction(Sender: TObject; Request: TWebRequest; Response: TWebResponse; var Handled: Boolean); begin try BaseDatos.Open; try if Not Transaccion.InTransaction Then Transaccion.Active:=True; if Not srhEmp.Prepared Then srhEmp.Prepared:=True; srhEmp.ParamByName ('pCI').AsString := Request.QueryFields.Values['pCI']; srhEmp.Open; {...... ....... .......} finally BaseDatos.Close(); end; except on E:Exception do begin Response.SendRedirect('/formularios/error.htm'); end; end; Handled := true; end; As can be observed this process does not carry too Thanks to Roman Walther for his article http://www.delphi3000.com/article.asp?ID=917 it was very useful Regards