visual foxpro database publishing on the internet
DESCRIPTION
™. Visual FoxPro Database Publishing on the Internet. by Rick Strahl West Wind Technologies http://www.west-wind.com/. Internet Development. Businesses are expanding their operations onto the Internet Internet Development is exploding Active, Database Applications are in high demand. - PowerPoint PPT PresentationTRANSCRIPT
Visual FoxProVisual FoxProDatabase Publishing on the Database Publishing on the Internet Internet
™
by Rick Strahlby Rick Strahl West Wind TechnologiesWest Wind Technologies
http://www.west-wind.com/http://www.west-wind.com/
Internet DevelopmentInternet Development
Businesses are expanding their Businesses are expanding their operations onto the Internetoperations onto the Internet
Internet Development is explodingInternet Development is exploding
Active,Active, Database Applications are Database Applications are in high demandin high demand
Why build Web Applications?Why build Web Applications?Issues that make the Web hotIssues that make the Web hot
Distribute widelyDistribute widely
Administer centrallyAdminister centrally
Universal Client InterfaceUniversal Client Interface
Application Platform of the futureApplication Platform of the future
Limitations of Web ApplicationsLimitations of Web ApplicationsOr: Two steps forward, one step back...Or: Two steps forward, one step back...
Configuration issuesConfiguration issues
Interface limitations of HTMLInterface limitations of HTML
Indirect data accesss through serverIndirect data accesss through server
Mostly non-visual developmentMostly non-visual development
Server based programming modelServer based programming model
BrowserBrowser provides the provides the ActiveActive interface interface Web ServerWeb Server provides data / application provides data / application
connectivityconnectivity The The Internet Server API (ISAPI)Internet Server API (ISAPI) is the is the
building block for server side building block for server side extensionsextensions
Web BrowserDisplays HTML
Server sideServer sideClient sideClient side
HTTPHTTPHTTPHTTP WebWebserverserverWebWeb
serverserver
Server ExtensionsServer ExtensionsISAPI/CGIISAPI/CGI
Server ExtensionsServer ExtensionsISAPI/CGIISAPI/CGI
StaticStatic
HTML HTML
PagesPages
ActiveX ActiveX Controls/Controls/
JavaJava
ActiveX ActiveX Controls/Controls/
JavaJava
‘‘TheWallTheWall’’
BrowserBrowserScripting:Scripting:VBScriptVBScript
JavaScriptJavaScript
BrowserBrowserScripting:Scripting:VBScriptVBScript
JavaScriptJavaScript Dynamic Dynamic Data and Data and DatabaseDatabase
How the Active Web Works
Active Active DocumentsDocuments
Active Active DocumentsDocuments
Web ServerWeb ServerHREF=“/cgi-bin/cgi.exe?Parms”HREF=“/cgi-bin/cgi.exe?Parms”
Web ServerWeb ServerHREF=“/cgi-bin/cgi.exe?Parms”HREF=“/cgi-bin/cgi.exe?Parms”
CGI.exe (1)(EXE, CMD, BAT)(EXE, CMD, BAT)
CGI.exe (1)(EXE, CMD, BAT)(EXE, CMD, BAT)
CGI.exe (n) (EXE, CMD, BAT)(EXE, CMD, BAT)
CGI.exe (n) (EXE, CMD, BAT)(EXE, CMD, BAT)
Common Gateway InterfaceCommon Gateway InterfaceTraditional Web InterfaceTraditional Web Interface
CGI.exe (2)(EXE, CMD, BAT)(EXE, CMD, BAT)
CGI.exe (2)(EXE, CMD, BAT)(EXE, CMD, BAT)
New system process for each instance of script.New system process for each instance of script.(relatively slow, resource intensive)(relatively slow, resource intensive)
Web ServerWeb ServerHREF=“/scripts/isapi.dll?parms”HREF=“/scripts/isapi.dll?parms”
MyISAPI (1,2..n)(Multithreaded, In-Process DLL)
Loads DLL once after which it stays resident, Loads DLL once after which it stays resident, processing multiple requests simultaneously. processing multiple requests simultaneously.
OtherISAPI(Multithreaded, In-Process DLL)
Internet Server API (ISAPI)Internet Server API (ISAPI)Extending the Architecture within the ServerExtending the Architecture within the Server
OD
BC
OD
BC
MA
PI
MA
PI
Active Server Active Server PagesPages
(Denali)(Denali)
Active Server Active Server PagesPages
(Denali)(Denali)
Internet Internet Database Database
ConnectorConnector
Internet Internet Database Database
ConnectorConnector
ExchangeExchangeWeb Web
ConnectorConnector
ExchangeExchangeWeb Web
ConnectorConnector
Microsoft Internet Information ServerMicrosoft Internet Information ServerMicrosoft Internet Information ServerMicrosoft Internet Information Server
Static contentStatic content(e.g., HTML)(e.g., HTML)
Static contentStatic content(e.g., HTML)(e.g., HTML)
Microsoft Microsoft ExchangeExchange
Microsoft Microsoft ExchangeExchange
Custom scripts, Custom scripts, Interfaces to other Interfaces to other applications etc.applications etc.
Custom scripts, Custom scripts, Interfaces to other Interfaces to other applications etc.applications etc.
DatabasesDatabases(FoxPro, SQL, (FoxPro, SQL,
Access etc.)Access etc.)
DatabasesDatabases(FoxPro, SQL, (FoxPro, SQL,
Access etc.)Access etc.)
ISAPIISAPIISAPIISAPI
Custom Custom ISAPI ISAPI
ScriptingScripting
Custom Custom ISAPI ISAPI
ScriptingScripting
Internet Server API (ISAPI) The extension interface for IIS
Getting StartedGetting StartedWhat you need for building Web appsWhat you need for building Web apps
Fast Pentium box Fast Pentium box (133Mhz/32-64megs)(133Mhz/32-64megs)
WindowsNT WindowsNT ((recommendedrecommended))
Web ServerWeb Server Connector Interface/ApplicationConnector Interface/Application Web browserWeb browser Basic HTML skillsBasic HTML skills Everything can run on 1 box!Everything can run on 1 box!
Connecting Visual FoxPro DataConnecting Visual FoxPro DataSome of the tools available for IISSome of the tools available for IIS
Active Server Pages (IIS 3.0)Active Server Pages (IIS 3.0)
FoxISAPI connector (OLE)FoxISAPI connector (OLE)
West Wind Web Connection West Wind Web Connection
(ISAPI/OLE)(ISAPI/OLE)
Active Server Pages (IIS 3.0)Active Server Pages (IIS 3.0)Server side scripting for IISServer side scripting for IIS
Object Based ArchitectureObject Based Architecture
Tight integration with IISTight integration with IIS Database Connectivity with Active Data Database Connectivity with Active Data
Objects (ADO)Objects (ADO)
Supports external object creationSupports external object creation
Several sophisticated objects are built-inSeveral sophisticated objects are built-in
ASP.DLLASP.DLL(ISAPI Extension)(ISAPI Extension)
Active Server ArchitectureActive Server ArchitectureComponents GaloreComponents Galore
Active DataActive DataObjectsObjects(ODBC)(ODBC)
Active DataActive DataObjectsObjects(ODBC)(ODBC)
Response/RequestResponse/RequestObjectsObjects
(Input and Output)(Input and Output)
Response/RequestResponse/RequestObjectsObjects
(Input and Output)(Input and Output)Server ObjectServer Object(System Services)(System Services)Server ObjectServer Object(System Services)(System Services)
Scripting EngineScripting Engine(VBScript/JavaScript)(VBScript/JavaScript)Scripting EngineScripting Engine(VBScript/JavaScript)(VBScript/JavaScript)
Session/ApplicationSession/ApplicationObjectsObjects
(Keeping State)(Keeping State)
Session/ApplicationSession/ApplicationObjectsObjects
(Keeping State)(Keeping State)
Active Data ObjectsActive Data Objects
Lightweight ODBC ConnectorLightweight ODBC Connector Implements OLE DB (ODBC 3.5)Implements OLE DB (ODBC 3.5) Based on Visual Basic’s Remote Based on Visual Basic’s Remote
Data ObjectData Object It’s fast especially when tied to a It’s fast especially when tied to a
persistent connection object!persistent connection object! Implemented as Automation Object.Implemented as Automation Object.
ASP Scripting EngineASP Scripting EngineHTML containing VBScript codeHTML containing VBScript code
ASP Scripting EngineASP Scripting EngineHTML containing VBScript codeHTML containing VBScript code
WebWeb ServerServer
ADO Data ObjectADO Data Object(ODBC Data Access)(ODBC Data Access)
ADO Data ObjectADO Data Object(ODBC Data Access)(ODBC Data Access)
OLE DLL ServerOLE DLL Server(InProcess)(InProcess)
OLE DLL ServerOLE DLL Server(InProcess)(InProcess)
OLE EXE ServerOLE EXE Server(OutOf Process)(OutOf Process)
TClass::Tmethod()TClass::Tmethod()
OLE EXE ServerOLE EXE Server(OutOf Process)(OutOf Process)
TClass::Tmethod()TClass::Tmethod()Creates Object Reference:<% oServer=Server.CREATEOBJ(“Tserver.TClass“) cVar=oServer.Tmethod(“Parm1“,1) %>
Creates Object Reference:<% oServer=Server.CREATEOBJ(“Tserver.TClass“) cVar=oServer.Tmethod(“Parm1“,1) %>
Automation Server Access Automation Server Access
HREF=“MyPage.ASP”HREF=“MyPage.ASP”
Active Server SummaryActive Server Summary
Pros:Pros: Tight Integration with IISTight Integration with IIS No hassle configurationNo hassle configuration Very easy for simple active contentVery easy for simple active content
Cons:Cons: Code ManagementCode Management Automation Server ScalabilityAutomation Server Scalability Scripting Language LimitationsScripting Language Limitations
FoxISAPIFoxISAPIConnecting VFP Automation serversConnecting VFP Automation servers
Direct link from Web pagesDirect link from Web pages ISAPI DLL creates persistent ISAPI DLL creates persistent
Automation object Automation object DLL does equivalent of:DLL does equivalent of:
Passes form vars in parameter Passes form vars in parameter Passes server vars in INI filePasses server vars in INI file
oServer=CREATEOBJECT(“TOleServer.TOleClass”)oServer.YourMethod(“UserId=1”,”c:\temp\fox2.ini”)oServer=CREATEOBJECT(“TOleServer.TOleClass”)oServer.YourMethod(“UserId=1”,”c:\temp\fox2.ini”)
WebWeb ServerServer
FOXISAPI.DLLFOXISAPI.DLL(HREF=“foxisapi.dll/Server.Class.Method”)(HREF=“foxisapi.dll/Server.Class.Method”)
multithreaded/running InProcessmultithreaded/running InProcess
Visual FoxPro OLE ServerVisual FoxPro OLE Server(loaded once then stays in memory)(loaded once then stays in memory)
Method1Method1 Method2Method2 MethodnMethodn
passespassesHTML FormHTML Form
DataData
passespassesHTML FormHTML Form
DataData
returns returns HTML HTML
DocumentDocument
returns returns HTML HTML
DocumentDocument
How FoxISAPI works
DEFINE CLASS TFoxISAPI AS Custom OLEPUBLIC
FUNCTION HelloworldLPARAMETER lcFormVars, lcIniFile, lnReleaseFlagLOCAL lcOutput#DEFINE CR CHR(13)+CHR(10)
*** HTTP header - REQUIRED on each request!*** System DefineslcOutput="HTTP/1.0 200 OK"+CR+; "Content-type: text/html"+CR+CRlcOutput=lcOutput+;"<HTML><BODY>"+CR+;"<H1>Hello World from Visual FoxPro</H1><HR>"+CR+;"This page was generated by Visual FoxPro...<HR>"+CR+;"</HTML></BODY>"RETURN lcOutput
ENDDEFINE
DEFINE CLASS TFoxISAPI AS Custom OLEPUBLIC
FUNCTION HelloworldLPARAMETER lcFormVars, lcIniFile, lnReleaseFlagLOCAL lcOutput#DEFINE CR CHR(13)+CHR(10)
*** HTTP header - REQUIRED on each request!*** System DefineslcOutput="HTTP/1.0 200 OK"+CR+; "Content-type: text/html"+CR+CRlcOutput=lcOutput+;"<HTML><BODY>"+CR+;"<H1>Hello World from Visual FoxPro</H1><HR>"+CR+;"This page was generated by Visual FoxPro...<HR>"+CR+;"</HTML></BODY>"RETURN lcOutput
ENDDEFINE
HREF=“/scripts/foxisapi.dll/TDevCon.TFoxIsapi.Helloworld?”
Hello World with FoxISAPI
FoxISAPI Method RulesFoxISAPI Method Rules
Must take 3 parametersMust take 3 parameters lcFormVar - HTML Form vars or lcFormVar - HTML Form vars or
‘parameters’ passed on the URL‘parameters’ passed on the URL lcIniFile - filename containing server varlcIniFile - filename containing server var lnReleaseFlag - Set to keep or release server lnReleaseFlag - Set to keep or release server
reference.reference.
Must return HTTP compliant outputMust return HTTP compliant output HTML document including HTTP headerHTML document including HTTP header Use custom HTTP headers for things like Use custom HTTP headers for things like
authentication, redirection, Cookies etc.authentication, redirection, Cookies etc.
Set up for FoxISAPISet up for FoxISAPI OLE Server must be registeredOLE Server must be registered Copy FoxISAPI.dll into script dirCopy FoxISAPI.dll into script dir
Directory must have Web Server Directory must have Web Server Execute rights set! Execute rights set!
Run DCOMCnfg on NT 4.0Run DCOMCnfg on NT 4.0Add IUSR_ account to default rightsAdd IUSR_ account to default rightsSet user to Interactive user on the Set user to Interactive user on the
specific serverspecific serverNeed to re-run whenever server is Need to re-run whenever server is
rebuiltrebuilt
FoxISAPI OLE InstancingFoxISAPI OLE Instancing InProcess DLLInProcess DLL
Very fastVery fast Only 1 VFP server can be InProcessOnly 1 VFP server can be InProcess
MultiUse MultiUse (Out of Process EXE)(Out of Process EXE)
Slightly slowerSlightly slower Multiple different serversMultiple different servers
Single Use Single Use Use for multiple pooled serversUse for multiple pooled servers Same server can be instanced more Same server can be instanced more
than oncethan once
Starter FoxISAPI classStarter FoxISAPI classProvided on the CDProvided on the CD
Send/SendLn()Send/SendLn() Send text to outputSend text to output StandardPage()StandardPage() Generates a full HTML pageGenerates a full HTML page ContentTypeHeader()ContentTypeHeader() Adds HTTP headerAdds HTTP header StartRequest()StartRequest() Called to set up a request. Called to set up a request.
Decodes input vars Decodes input vars and and clears the clears the output property.output property.
GetFormVar()GetFormVar() Retrieves a form variable Retrieves a form variable passed in with the first passed in with the first
parameter.parameter. GetCGIVar()GetCGIVar() Retrieves a server/browser Retrieves a server/browser
variable from the INI variable from the INI file.file.
ReleaseServer()ReleaseServer() Standard method that releases Standard method that releases the OLE server.the OLE server.
* TFoxISAPI :: TestMethodFUNCTION TestMethodLPARAMETER lcFormVars, lcIniFile, lnReleaseFlagLOCAL lcOutput, lcUserId, lcName
*** Decode the Form Vars and assign INI file to class propertyTHIS.StartRequest(lcFormVars,lcIniFile)
*** Must always add a content Type Header to output firstTHIS.HTMLContentTypeHeader()
lcUserId=THIS.GetFormVar("UserId")lcName=THIS.GetFormVar("UserName")
THIS.SendLn("<HTML><BODY>")THIS.SendLn("<H1>Hello World from Visual FoxPro</H1><HR>")THIS.SendLn("The current time is: "+time()+"<p>")
THIS.SendLn("<b>Encoded Form/URL variables:</b> "+lcFormVars+"<BR>")THIS.SendLn("<b>Decoded UserId:</b> "+ lcUserId+"<p>")THIS.SendLn([To retrieve the Browser use ]+; [THIS.GetCGIVar("HTTP_USER_AGENT","ALL_HTTP"): ]+; THIS.GetCGIVar("HTTP_USER_AGENT","ALL_HTTP") )THIS.SendLn("<HR></HTML></BODY>")
RETURN THIS.cOutput
* TFoxISAPI :: TestMethodFUNCTION TestMethodLPARAMETER lcFormVars, lcIniFile, lnReleaseFlagLOCAL lcOutput, lcUserId, lcName
*** Decode the Form Vars and assign INI file to class propertyTHIS.StartRequest(lcFormVars,lcIniFile)
*** Must always add a content Type Header to output firstTHIS.HTMLContentTypeHeader()
lcUserId=THIS.GetFormVar("UserId")lcName=THIS.GetFormVar("UserName")
THIS.SendLn("<HTML><BODY>")THIS.SendLn("<H1>Hello World from Visual FoxPro</H1><HR>")THIS.SendLn("The current time is: "+time()+"<p>")
THIS.SendLn("<b>Encoded Form/URL variables:</b> "+lcFormVars+"<BR>")THIS.SendLn("<b>Decoded UserId:</b> "+ lcUserId+"<p>")THIS.SendLn([To retrieve the Browser use ]+; [THIS.GetCGIVar("HTTP_USER_AGENT","ALL_HTTP"): ]+; THIS.GetCGIVar("HTTP_USER_AGENT","ALL_HTTP") )THIS.SendLn("<HR></HTML></BODY>")
RETURN THIS.cOutput
HREF=“/scripts/foxisapi.dll/TDevCon.TFoxIsapi.TestMethod?”
Method example with FoxISAPI class
FoxISAPI SummaryFoxISAPI Summary
Pros:Pros: Full support for Visual FoxProFull support for Visual FoxPro Real Development EnvironmentReal Development Environment Excellent performanceExcellent performance
Cons:Cons: Difficult First Time ConfigurationDifficult First Time Configuration No Web specific code supportNo Web specific code support Doesn’t run on non-ISAPI servers or Doesn’t run on non-ISAPI servers or
Windows ‘95Windows ‘95
West Wind Web ConnectionWest Wind Web Connection
Extensive Visual FoxPro framework Extensive Visual FoxPro framework for Web developmentfor Web development
Support for multiple sessionsSupport for multiple sessions Works with Automation and File based Works with Automation and File based
messaging interchangeably messaging interchangeably Scalable across multiple machines Scalable across multiple machines Real-time, live debuggingReal-time, live debugging Server ManagementServer Management
Web Browser
WebWebServerServerWebWeb
ServerServerVisualVisual
FoxProFoxProData ServerData Server
(already loaded)(already loaded)
DatabaseDatabase
HT
ML
Doc
um
ent
HT
ML
Link
wc.dllwc.dll(ISAPI)(ISAPI)
Server and Form Data
returns HTML Doc
FoxPro UserFoxPro User CodeCode
ScriptedScriptedHTMLHTML
Web Connection Data ServerWeb Connection Data Server
wwServerwwServerVisual FoxPro form classVisual FoxPro form class
handles request routing onhandles request routing onincoming requests.incoming requests.
wwServerwwServerVisual FoxPro form classVisual FoxPro form class
handles request routing onhandles request routing onincoming requests.incoming requests.
invokesinvokeswwServer::Process()wwServer::Process()
Routes request to Routes request to your PRG fileyour PRG file
wwServer::Process()wwServer::Process()
Routes request to Routes request to your PRG fileyour PRG file
MyPRGMyPRGcreates new Process objectcreates new Process objectand calls Process methodand calls Process method
MyPRGMyPRGcreates new Process objectcreates new Process objectand calls Process methodand calls Process method
CGIProcess ClassCGIProcess ClassContains Contains MyMethod() thatMyMethod() that
creates HTML output.creates HTML output.Class can containClass can containmultiple methods.multiple methods.
CGIProcess ClassCGIProcess ClassContains Contains MyMethod() thatMyMethod() that
creates HTML output.creates HTML output.Class can containClass can containmultiple methods.multiple methods.
Returns HTML objectReturns HTML object
To process this URL:To process this URL:
wc.dll?MyPRG~MyMethodwc.dll?MyPRG~MyMethod
How your code gets called
wwServerwwServer
Visual FoxProVisual FoxProform that’s anform that’s anOLEPUBLICOLEPUBLIC
Automation ObjectAutomation Objectoror uses a timer uses a timer
to poll for requeststo poll for requestson disk.on disk.
wwServerwwServer
Visual FoxProVisual FoxProform that’s anform that’s anOLEPUBLICOLEPUBLIC
Automation ObjectAutomation Objectoror uses a timer uses a timer
to poll for requeststo poll for requestson disk.on disk.
How your code gets called
Creates Process Object
returns HTML object
DEFINE CLASS MyProcess...
Procedure ProcessloCGI=THIS.oCGIlcParam=loCGI.GetParam(1)
*** Any ‘global processing’ here*** Check for Cookies, User Ids etc.
*** Route to appropriate methodCASE PEMSTATUS(THIS,lcParam,5) =EVAL("THIS."+lcParam+"()")
RETURN
PROCEDURE CUSTLIST <Your processing goes here> <Create HTML document file>RETURN
DEFINE CLASS MyProcess...
Procedure ProcessloCGI=THIS.oCGIlcParam=loCGI.GetParam(1)
*** Any ‘global processing’ here*** Check for Cookies, User Ids etc.
*** Route to appropriate methodCASE PEMSTATUS(THIS,lcParam,5) =EVAL("THIS."+lcParam+"()")
RETURN
PROCEDURE CUSTLIST <Your processing goes here> <Create HTML document file>RETURN
Web Connection FrameworkWeb Connection FrameworkSome of the features availableSome of the features available
Class framework for easy access to Class framework for easy access to CGI/HTML functionalityCGI/HTML functionality
Solid error handling schemeSolid error handling scheme Hit Logging, Mulitple Session Hit Logging, Mulitple Session
Management and Maintainence RoutinesManagement and Maintainence Routines HTML scripting from files or memosHTML scripting from files or memos Single method output of tables to HTMLSingle method output of tables to HTML Built-in support for many advanced Built-in support for many advanced
HTML/HTTP featuresHTML/HTTP features
*** wwCGIProcess :: CustListFUNCTION CustList
loCGI=THIS.oCGIloHTML=THIS.oHTMLlcClient=TRIM(UPPER(loCGI.GetFormVar(“Client“))
SELECT tt_cust.company FROM TT_CUST ; WHERE UPPER(tt_cust.company)=lcClient INTO CURSOR TQUERY ORDER BY company,Datein
IF _TALLY<1 THIS.ErrorMsg("No Matching Records found...") RETURNENDIF
*** HTML output creation followsloHTML.HTMLHeader("NWDS Customer List",; "Customer List Sample",”#FFFFFF”)loHTML.EnclosedText("H3","Time review for: "+lcClient)loHTML.SendLn(“<p>”)
*** Now show the table loHTML.ShowCursor()
loHTML.HTMLFooter()RETURN
*** wwCGIProcess :: CustListFUNCTION CustList
loCGI=THIS.oCGIloHTML=THIS.oHTMLlcClient=TRIM(UPPER(loCGI.GetFormVar(“Client“))
SELECT tt_cust.company FROM TT_CUST ; WHERE UPPER(tt_cust.company)=lcClient INTO CURSOR TQUERY ORDER BY company,Datein
IF _TALLY<1 THIS.ErrorMsg("No Matching Records found...") RETURNENDIF
*** HTML output creation followsloHTML.HTMLHeader("NWDS Customer List",; "Customer List Sample",”#FFFFFF”)loHTML.EnclosedText("H3","Time review for: "+lcClient)loHTML.SendLn(“<p>”)
*** Now show the table loHTML.ShowCursor()
loHTML.HTMLFooter()RETURN
Sample Processing Code
Tools summaryTools summary Check out Active Server for Check out Active Server for
sophisticated server scripting and sophisticated server scripting and connectivity to VFP via Auto serversconnectivity to VFP via Auto servers
For more control use Visual FoxPro as a For more control use Visual FoxPro as a Web data serverWeb data server
FoxISAPI provides powerful OLE FoxISAPI provides powerful OLE connectivity with an easy interfaceconnectivity with an easy interface
For a complete Fox based Web For a complete Fox based Web environment check out Web Connectionenvironment check out Web Connection
™