Royal Blue PowerPoint Template

Download Report

Transcript Royal Blue PowerPoint Template

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
Why build Web Applications?
Issues that make the Web hot

Distribute widely

Administer centrally

Universal Client Interface

Application Platform of the future
Limitations of Web Applications
Or: Two steps forward, one step back...

Configuration issues

Interface limitations of HTML

Indirect data accesss through server

Mostly non-visual development

Server based programming model

Browser provides the Active interface

Web Server provides data / application
connectivity

The Internet Server API (ISAPI) is the
building block for server side extensions
How the Active Web Works
Client side
Active
Documents
Web Browser
Server side
HTTP
Displays HTML
Browser
Scripting:
VBScript
JavaScript
ActiveX
Controls/
Java
‘TheWall’
Static
HTML
Pages
Web
server
Server Extensions
ISAPI/CGI
Dynamic
Data and
Database
Common Gateway Interface
Traditional Web Interface
CGI.exe (1)
CGI.exe (2)
CGI.exe (n)
(EXE, CMD, BAT)
(EXE, CMD, BAT)
(EXE, CMD, BAT)
New system process for each instance of script.
(relatively slow, resource intensive)
Web Server
HREF=“/cgi-bin/cgi.exe?Parms”
Internet Server API (ISAPI)
Extending the Architecture within the Server
MyISAPI (1,2..n)
OtherISAPI
(Multithreaded, In-Process DLL)
(Multithreaded, In-Process DLL)
Loads DLL once after which it stays resident,
processing multiple requests simultaneously.
Web Server
HREF=“/scripts/isapi.dll?parms”
Internet Server API (ISAPI)
The extension interface for IIS
Databases
(FoxPro, SQL,
Access etc.)
Exchange
Web
Connector
Custom scripts,
Interfaces to other
applications etc.
ODBC
Microsoft
Exchange
MAPI
Static content
(e.g., HTML)
Internet
Database
Connector
Active Server
Pages
(Denali)
Custom
ISAPI
Scripting
ISAPI
Microsoft Internet Information Server
Getting Started
What you need for building Web apps







Fast Pentium box (133Mhz/32-64megs)
WindowsNT (recommended)
Web Server
Connector Interface/Application
Web browser
Basic HTML skills
Everything can run on 1 box!
Connecting Visual FoxPro Data
Some of the tools available for IIS

Active Server Pages (IIS 3.0)

FoxISAPI connector (OLE)

West Wind Web Connection
(ISAPI/OLE)
Active Server Pages (IIS 3.0)
Server side scripting for IIS

Object Based Architecture

Tight integration with IIS

Database Connectivity with Active Data
Objects (ADO)

Supports external object creation

Several sophisticated objects are built-in
Active Server Architecture
Components Galore
Response/Request
Objects
Server Object
(Input and Output)
(System Services)
ASP.DLL
(ISAPI Extension)
Scripting Engine
(VBScript/JavaScript)
Active Data
Objects
Session/Application
Objects
(ODBC)
(Keeping State)
Active Data Objects





Lightweight ODBC Connector
Implements OLE DB (ODBC 3.5)
Based on Visual Basic’s Remote
Data Object
It’s fast especially when tied to a
persistent connection object!
Implemented as Automation Object.
Automation Server Access
ASP Scripting Engine
OLE EXE Server
HTML containing VBScript code
(OutOf Process)
TClass::Tmethod()
Creates Object Reference:
<% oServer=Server.CREATEOBJ(“Tserver.TClass“)
cVar=oServer.Tmethod(“Parm1“,1) %>
ADO Data Object
OLE DLL Server
(ODBC Data Access)
(InProcess)
Web Server
HREF=“MyPage.ASP”
Active Server Summary
Pros:



Tight Integration with IIS
No hassle configuration
Very easy for simple active content
Cons:



Code Management
Automation Server Scalability
Scripting Language Limitations
FoxISAPI
Connecting VFP Automation servers



Direct link from Web pages
ISAPI DLL creates persistent
Automation object
DLL does equivalent of:
oServer=CREATEOBJECT(“TOleServer.TOleClass”)
oServer.YourMethod(“UserId=1”,”c:\temp\fox2.ini”)


Passes form vars in parameter
Passes server vars in INI file
How FoxISAPI works
Visual FoxPro OLE Server
(loaded once then stays in memory)
Method1
Method2
Methodn
returns
HTML
Document
passes
HTML Form
Data
FOXISAPI.DLL
(HREF=“foxisapi.dll/Server.Class.Method”)
multithreaded/running InProcess
Web Server
Hello World with FoxISAPI
HREF=“/scripts/foxisapi.dll/TDevCon.TFoxIsapi.Helloworld?”
DEFINE CLASS TFoxISAPI AS Custom OLEPUBLIC
FUNCTION Helloworld
LPARAMETER lcFormVars, lcIniFile, lnReleaseFlag
LOCAL lcOutput
#DEFINE CR CHR(13)+CHR(10)
*** HTTP header - REQUIRED on each request!
*** System Defines
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+;
"</HTML></BODY>"
RETURN lcOutput
ENDDEFINE
FoxISAPI Method Rules

Must take 3 parameters
lcFormVar - HTML Form vars or
‘parameters’ passed on the URL
 lcIniFile - filename containing server var
 lnReleaseFlag - Set to keep or release server
reference.


Must return HTTP compliant output
HTML document including HTTP header
 Use custom HTTP headers for things like
authentication, redirection, Cookies etc.

Set up for FoxISAPI


OLE Server must be registered
Copy FoxISAPI.dll into script dir
Directory
must have Web Server
Execute rights set!

Run DCOMCnfg on NT 4.0
Add
IUSR_ account to default rights
Set user to Interactive user on the
specific server
Need to re-run whenever server is
rebuilt
FoxISAPI OLE Instancing

InProcess DLL
 Very
fast
 Only 1 VFP server can be InProcess

MultiUse (Out of Process EXE)
 Slightly
slower
 Multiple different servers

Single Use
 Use
for multiple pooled servers
 Same server can be instanced more
than once
Starter FoxISAPI class
Provided on the CD

Send/SendLn()
StandardPage()
ContentTypeHeader()
StartRequest()

GetFormVar()

GetCGIVar()

ReleaseServer()



Send text to output
Generates a full HTML page
Adds HTTP header
Called to set up a request.
Decodes input vars and
clears the output property.
Retrieves a form variable
passed in with the first
parameter.
Retrieves a server/browser
variable from the INI file.
Standard method that releases
the OLE server.
Method example with FoxISAPI class
HREF=“/scripts/foxisapi.dll/TDevCon.TFoxIsapi.TestMethod?”
* TFoxISAPI :: TestMethod
FUNCTION TestMethod
LPARAMETER lcFormVars, lcIniFile, lnReleaseFlag
LOCAL lcOutput, lcUserId, lcName
*** Decode the Form Vars and assign INI file to class property
THIS.StartRequest(lcFormVars,lcIniFile)
*** Must always add a content Type Header to output first
THIS.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
FoxISAPI Summary
Pros:
Full support for Visual FoxPro
Real Development Environment
Excellent performance
Cons:
Difficult First Time Configuration
No Web specific code support
Doesn’t run on non-ISAPI servers or
Windows ‘95
West Wind Web Connection






Extensive Visual FoxPro framework
for Web development
Support for multiple sessions
Works with Automation and File based
messaging interchangeably
Scalable across multiple machines
Real-time, live debugging
Server Management
Web Connection Data Server
Web
Server
Server and Form Data
wc.dll
(ISAPI)
HTML Link
HTML Document
returns HTML Doc
Web Browser
Visual
FoxPro
Data Server
(already loaded)
FoxPro User
Code
Scripted
HTML
Database
How your code gets called
wwServer
Visual FoxPro form class
handles request routing on
incoming requests.
wwServer::Process()
invokes
To process this URL:
wc.dll?MyPRG~MyMethod
Routes request to
your PRG file
MyPRG
creates new Process object
and calls Process method
CGIProcess Class
Returns HTML object
Contains MyMethod() that
creates HTML output.
Class can contain
multiple methods.
How your code gets called
DEFINE CLASS MyProcess...
wwServer
Visual FoxPro
form that’s an
OLEPUBLIC
Automation Object
or uses a timer
to poll for requests
on disk.
Creates Process Object
Procedure Process
loCGI=THIS.oCGI
lcParam=loCGI.GetParam(1)
*** Any ‘global processing’ here
*** Check for Cookies, User Ids etc.
*** Route to appropriate method
CASE PEMSTATUS(THIS,lcParam,5)
=EVAL("THIS."+lcParam+"()")
RETURN
returns HTML object
PROCEDURE CUSTLIST
<Your processing goes here>
<Create HTML document file>
RETURN
Web Connection Framework
Some of the features available






Class framework for easy access to
CGI/HTML functionality
Solid error handling scheme
Hit Logging, Mulitple Session
Management and Maintainence Routines
HTML scripting from files or memos
Single method output of tables to HTML
Built-in support for many advanced
HTML/HTTP features
Sample Processing Code
*** wwCGIProcess :: CustList
FUNCTION CustList
loCGI=THIS.oCGI
loHTML=THIS.oHTML
lcClient=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...")
RETURN
ENDIF
*** HTML output creation follows
loHTML.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
Tools summary




Check out Active Server for
sophisticated server scripting and
connectivity to VFP via Auto servers
For more control use Visual FoxPro as a
Web data server
FoxISAPI provides powerful OLE
connectivity with an easy interface
For a complete Fox based Web
environment check out Web Connection
™