The FoxIsapi sample demonstrates how you can take Visual FoxPro forms and deploy them over the Internet or an Intranet.
NOTE: This sample code is provided to show the capabilities and flexibility of Visual FoxPro as an OLE Automation Server. Any modification made to this code will not be supported.
In the FoxIsapi sample the main class library is named ISAPI.VCX. In this library the Employee class inherits the ability to generate HTML code from the base class ISFORM. The ability to generate the HTML code gives the developer a way to display data or forms in a WEB page on the Internet. It also gives the developer a way to deploy an easy to maintain application on 4 different platforms:
1. Running from within Visual FoxPro
SET CLASSLIB TO isapi
ox = CreateObject("employee")
ox.show
2. Running as an independent Executable:
BUILD EXE foxis FROM foxis
This creates a FOXIS.EXE which is a Windows program that can be added to the start menu, started from the Explorer, etc.
3. Running as an OLE Server from any OLE client (Excel,Word,VB, VFP3, etc):
ox = CreateObject("foxis.employee")
ox.show
4. From an Internet Browser, which could be on another machine, such as a 286, running DOS, a Unix machine, a Mac, or a Personal Digital Assistant.
REQUIREMENTS:
This sample is only supported on Windows NT 3.51 Server running Microsoft's Internet Information Server (IIS). Microsoft's Internet Information Server can be downloaded, free, from HTTP://WWW.MICROSOFT.COM/INFOSERV. It requires Windows NT 3.51 Server with Service Pack 3 or higher to run.
The NT Server and IIS should be configured and working properly before running this sample.
If you're running NT 4.0, you'll have to configure the DCOMCNFG utility to grant rights to the web service to instantiate an OLE object. If your machine name is MYMAC, then you might have to add \MYMAC\IUSER_MYMAC as a user with full rights for "Default Access Permissions", "Default Launch Permissions", and "Default Configuration Permissions"
SETUP OF FOXISAPI:
To get things started, you need to follow all of the steps below:
1. First you will need a HTML page that contains a reference to a URL. For example, take the following code and put it in the WWWROOT\default.htm file.
<A HREF="/scripts/foxisapi.dll/FoxIS.employee.startup"> <I>VFP OLE CUSTOM SERVER DEMO PAGE</I> </A>
2. In the same HTML file cut and paste the following code:
This code will create a button on the page that will tell the server to execute any MS-DOS command, such as DIR, and it will return a page with the results of the command. If the command is "Reset" (default), then it will make the OLE Automation server release the first instance of the server as well as its own, thus releasing the OLE Automation server completely.
value="Fox Expression"> For example try: "today is "+ cdow(date()) or 45 * 3 or SYS(2004)
</FORM>
WARNING: An NT Service has no Desktop, so any commands or functions that produce UI (like MessageBox) will not appear on the server machine and will hang the server machine if you attempt to execute them. This means you should debug your server applications before deploying them. The sample shows that if an error occurs, you can generate an HTML page to return back to the client's browser.
3. Take the FOXISAPI.DLL file and put it in your INETSRV\SCRIPTS directory.
This DLL instantiates the OLE Server by issuing a CreateObject("foxis.employee") and invokes the Startup method on the object, which returns a generated HTML page. If the Custom Server has not been built yet, then the FOXISAPI.DLL returns an HTML error page.
To see if the DLL is loading and working, use a browser to connect to the NT server's machine name. For example, if your server's machine name is "myserver", then type "HTTP://myserver", without the quotation marks, as the URL to go to. The default.htm page will be displayed with a jump to "VFP OLE CUSTOM SERVER DEMO PAGE" and two command buttons. If you click the jump at this point, you will get an error HTML page that says, "FOXISAPI error". This will tell you that the dll is loaded.
4. Open the FOXIS project and change the cScriptDir property of the EMPLOYEE form in the class library ISAPI.VCX, to point to your INETSRV\SCRIPTS directory. It may be best to copy the entire project into the SCRIPTS directory, so that all the different ways of running the app will be able to access the data.
5. Copy the TESTDATA.DBC files (including EMPLOYEE.DBF) from the SAMPLES\DATA directory into the INETSRV\SCRIPTS directory.
6. Now, build the EXE with the name FOXIS. Once the initial build is complete, change the server option to be Multi Use by selecting from the menu Project, Project Info. Then choose the Servers tab and change the instancing to Multi Use. Once this is done, then build the EXE again.
7. Test to see if the OLE Automation Server works by issuing the following commands from the command window:
ox= CreateObject("foxis.employee")
ox.show && see if it works as a custom server
?ox.startup() && see if it returns HTML
It is much easier to debug OLE Automaton servers from an OLE client (like VFP) before instantiating it in FOXISAPI.
8. If the Server worked, and if you have Visual FoxPro 5.0 installed on the NT server and the EXE was built on the same NT server, copy the FOXIS.EXE into the SCRIPTS directory. If you don't have VFP 5.0 installed on the NT server you will have to use the Setup Wizard to install the EXE to the SCRIPTS directory on the NT server. This will allow the OLE Automation Server to be registered on the NT Server.
9. You are now ready to run it from a browser. As you did in step number 3, connect to your NT server's machine name. Your default.htm page should look the same as it did in step 3, but if you now click the jump, it should return a page that shows you the data from the Employee table on the server.
OTHER INFORMATION:
For each Web site hit, the OLE server gets instantiated, generates an HTML page, and gets released with the Release() call in CallObject() in FOXISAPI.CPP. This means the entire VFP runtime will start up and shut down for each web hit.
If the OLE Custom Server is registered as Multi-Use, and the Release() is not call ed, then the first web hit will start up the server, but subsequent web hits will use the same instance of the server, making performance much better. Thus an instancing scheme is employed in the sample: If it's the first instance, don't release. If it's subsequent instances, then release as normal. To force a release, click on DOS button with the Value set to "Reset".
If you want to run FOXISAPI.DLL under the C debugger, do this: Uncomment the INT 3 breakpoint in HttpExtensionProc, rebuild, then start MSDEV dynamically attaching to the processid of INETINFO.EXE (Start MSDEV -p <PID>). When the breakpoint gets hit, you're in the debugger.
You don't have to shut down the WWWserver every time to change the OLE server. An easy way to debug/rebuild custom servers is to: With EXE servers, when you want to rebuild, just kill the EXE server process (use the RESET method above, or you can use TLIST and KILL from the Win32sdk to list/kill individual processes, or you can also use PVIEW.) This is much better than shutting down/restarting WWW services.
Note: The paramlen and buflen are #DEFINEd to be 1024 and 4096 in foxisapi.cpp. If you are expecting to receive large strings of text as parameters, you can increase these settings and recompile foxisapi.dll