Wiki Home

Fox ISAPIexample


Namespace: VB
Fox ISAPI example

Skipping all of the important details that you will need to know later, here is what it takes to make something work.
  1. Install: NT Server 4.0, SP3, ie4 (fat fs), VFP, Mdac, VS SP3, IIS (part of Nt Option Pack 3), NT SP6
  2. Copy ...vfp98\foxisapi.dll into \inetpub\scripts
  3. create project MyFoxProj
  4. put the code below into program1.prg
  5. BUILD EXE MyFoxServer FROM MyFoxProj
  6. In IE (or any browser): http://localhost/scripts/foxisapi.dll/MyFoxServer.MyFoxClass.HelloWorld

#DEFINE CR CHR(13)+CHR(10)

DEFINE CLASS MyFoxClass AS Custom OLEPUBLIC

cVersion = "1.1"

FUNCTION Helloworld
LPARAMETER lcFormVars, lcIniFile, lnReleaseFlag
LOCAL lcOutput

lcOutput="HTTP/1.0 200 OK"+CR+;
         "Content-type: text/html"+CR+CR

lcOutput=lcOutput+;
  "<HTML><BODY>"+CR+;
  "<H1>Hello World from Visual FoxPro</H1><HR>"+CR+;
  "This page was generated by Visual FoxPro...<HR>"+CR+;
  "At: " + ttoc( datetime() )+CR+;
  "</HTML></BODY>"

RETURN lcOutput

ENDDEFINE


Take a look at Fox Trails' RenderVml function. It can be used independent of Fox Trails for rendering html from Foxpro. Makes the code easier to read and gives a nice separation of concerns, allowing web designers to work on the layout and coders to maintain the logic. -- Brian Marquis

MyFoxClass
#DEFINE CR CHR(13)+CHR(10)

DEFINE CLASS MyFoxClass AS Custom OLEPUBLIC

cVersion = "1.1"

FUNCTION Helloworld
LPARAMETER lcFormVars, lcIniFile, lnReleaseFlag
LOCAL lcOutput
lcOutput = RenderVml("Hello.vml",this)
RETURN lcOutput

ENDDEFINE

Hello.vml
HTTP/1.0 200 OK
Content-type: text/html

<HTML>
<BODY>
  <H1>Hello World from Visual FoxPro</H1><HR>
  This page was generated by Visual FoxPro...<HR>
  At: <<datetime()>>
  </BODY>
  </HTML>


RenderVml.prg
PARAMETERS lcVml, loController, llCache
LOCAL lcScript,lcController, llCompile
LOCAL lcFxp, lcMask, lcPrg
PRIVATE pcHtml
pcHtml = ""
IF ISNULL(loController)
	lcController = "controller"
ELSE
	lcController = loController.Class
ENDIF

*-- read vml file
lcScript = FILETOSTR(lcVml)

pcHtml = ""
*-- prepend our parameters
lcScript = "PARAMETERS "+lcController+CHR(13)+;
	     "TEXT TO pcHtml NOSHOW TEXTMERGE"+ CHR(13)+;
	     lcScript

*-- convert Foxpro commands <% ... %> into vfp code blocks
lcScript = STRTRAN(lcScript ,"%>",CHR(13)+;
             "TEXT TO pcHtml NOSHOW TEXTMERGE ADDITIVE"+CHR(13))
lcScript = STRTRAN(lcScript ,"<%",CHR(13)+"ENDTEXT"+CHR(13))

*-- add closing endtext statement
lcScript = lcScript + CHR(13) + ;
		     "ENDTEXT"+ CHR(13)
EXECSCRIPT(lcScript,loController )

RETURN pcHtml

If you have trouble: _ Fox Isapi Example Diag
It took me about 2 weeks of doing things wrong; this is cherry picking out what I did right. I may have missed something, and I also changed a few things to make it more clear. So I may have messed up something in this example. If you have any trouble, be sure and ask about it. -- CFK
The original with all the details (and typos): http://www.west-wind.com/presentations/foxisapi/foxisapi.htm
NT Option pack: http://www.microsoft.com/ntserver/nts/downloads/recommended/NT4OptPk/default.asp
Contributors: Carl Karsten, Craig Pilks, Jeff Simon, Rick Strahl, Erik Kesteloot
Category Web Development
( Topic last updated: 2008.04.22 07:17:55 PM )