The FoxIsapi sample demonstrates how you can take Fox forms and deploy them over the Internet or an internal Intranet. To get this sample running, see the section below "Getting things started"
The Employee Class in the ISAPI Class Library inherits the ability to generate HTML from the base class ISFORM in the same library. This enables the developer to deploy an easily maintainable 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
Now you have 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 controller (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: You'll need some sort of ISAPI compatible Server Microsoft's Internet Information Server can be downloaded free from www.microsoft.com. It requires NT 3.51 Server with Service Pack 3.
You can install NT 3.51 Server on top of NT Workstation with no problem. You can also have a dual or triple boot machine.
Warning: an NT Service has no Desktop, so any UI will not appear on the server machine. 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.
If you're using NT 4.0, you'll have to run the DCOMCNFG utility to configure DCOM to give rights to the IIS service to instantiate OLE objects. Because NT 4.0 is still in Beta, the way to do this has been changing.
Getting Things Started: To get things started, you 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>
Then use a browser (which can be on the same machine) and connect to YourMachineName. Thus, if your machine name were "foobar", then type "foobar" as the URL to go to. This will bring up the default.htm page on the server named "foobar"
Take the FOXISAPI.DLL file and put it in your INETSRV\SCRIPTS directory. Then use your web browser to hit the href above. If you get an error HTML page that says FOXISAPI error, then you know the DLL is being loaded and is working.
It does a CreateObject("foxis.employee") and invokes the Startup method on the object, which returns a generated HTML page. If the Custom Server hasn't been built yet, then the FOXISAPI.DLL returns an HTML error page.
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 an HTML button:
<input name="Cmd" value = "Reset"><input type="submit" value="Dos Command">
</form>
(Note: cut & paste this HTML to get it right!)
You can actually put any valid DOS command in here and it will be executed on the server machine. If the command is "Reset" (default), then it will make the custom server release the first instance as well as it's own, thus releasing the OLE server completely.
You can evaluate any Fox expression too (don't try MessageBox, or it will hang the server):
value="Fox Expression"> like "today is "+ cdow(date()) or 45 * 3 or SYS(2004)</form>
Open the FOXIS project and change the cScriptDir property of EMPLOYEE to point to your inetsrv\scripts directory. It may be best to copy the entire project into that directory, so that all the different ways of running the app will be able to access the data.
Copy the TESTDATA.DBC files (including EMPLOYEE.DBF) into the scripts directory. If you want the employee's sorted in last name order,
USE EMPLOYEE and INDEX ON UPPER(last_name+first_name) TAG name.
Test to see if the app works: "DO MAIN" from the Command window
Build the EXE once, change the server option to MultiUse: from PJX>Project Info>Servers, then build the EXE again.
Test to see if it works from the Dos prompt, start the EXE:
START FOXIS.EXE
Test to see if the Custom server works:
ox= CreateObject("foxis.employee")
ox.show && see if it works as a custom server
?ox.startup() && see if it returns HTML
It's much easier to debug custom servers from an ole controller (like vfp) before instantiating it in foxisapi.
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. This works in NT4.0 and NT 3.51
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: 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. In NT4.0, you can use the taskman to kill your cust server process.) This is much better than shutting down/restarting WWW services.