Using wwBusiness with Web Data

wwBusiness can work with data that is retrieved over the Web from a Web Connection (or ASP) application. This accomplished through a special connector running on the server that sends the data requests from the client to the Web Server for execution. The server piece is implemented using the wwHTTPSQLServer class, while the wwBusiness client application uses the wwHTTPSQL class to execute SQL statements against the server. This server piece must be implementedusing a few lines of FoxPro code that configure the data connection and set security options on the Web Server using Web Connection, ASP or other FoxPro based Web backend that can run the wwHTTPSQLServer class.

![](IMAGES%5CMISC%5CWWBUSINESSWEBDATA.JPG)

Currently, only SQL Server is supported as a backend although Visual FoxPro data will work in some situations especially for data retrieval. Automatic INSERT and UPDATE operations however will fail with memo fields that exceed 255 characters of data.

Using wwBusiness with Web Data is very easy once the server side is set up and working. All you have to do is set nDataMode to 4 and either set the cServerUrl to the URL configured for the Web Data Service or call the SetHTTPSQLObject with an already configued wwHTTPSQL object (if you need special HTTP configuration for security, proxy support etc.). AFter that all calls to the business object can proceed the same way as with local data.

oDev = CREATEOBJECT("cDeveloper")
oDev.nDataMode = 4
oDev.cServerUrl = "http://localhost/wconnect/wc.dll?http~HTTPSQL_wwDevRegistry"

* ** Create the wwHTTPSQL object - (recommended, but not required if you don't modify the HTTP settings)
oDev.Open()

* ** Optional - configure any HTTP settings you need using wwHTTP properties
* oDev.oHTTPSQL.cUsername = "rick"
* oDev.oHTTPSQL.cPassword = "keepguessingbuddy"
* oDev.oHTTPSQL.nConnectTimeout = 40
* oDev.oHTTPSQL.nTransportMode = 2  && Transfer VFP cursors without XML

* ** Execute a raw SQL statement against the server
IF odev.Execute("delete wwDevregistry where pk > 220") < 0
   ?  oDev.cErrorMsg
ENDIF

* ** Run a query that returns a cursor
lnRecords = oDev.Query("select * from wwDevRegistry where company > 'L' ") 
IF oDev.lError
	? oDev.cErrorMsg
ELSE
	BROWSE
ENDIF

* ** Load one object
 oDev.Load(8)
? oDev.oData.Company
? oDev.oData.Name
 oDev.oData.Company = "West Wind Technologies"
IF !oDev.Save()
	? oDev.cErrorMsg
ENDIF

* ** Create a new record
? oDev.New()

loData = oDev.oData

loData.Company = "TEST COMPANY"
loData.Name = "Rick Sttrahl"
? oDev.Save()

* ** Show added rec 
? oDev.Query()
GO BOTT
BROWSE

Remember this requires that the server url be configured with a wwHTTPSQLServer backend. But on the client side as you can see you can run the same operations that you can run against a business object with local data and expect the same results.

For more info on SQL commands that you can process and how to pass named parameters to the wwHTTPSQL member of wwBusiness see the wwHTTPSQL documentation.

Setting up the server side

In order to use the wwBusiness object with Web data you have to configure the server to handle your requests. You do this by creating a Web Connection process class method that acts as a front end to the wwHTTPSQLServer class (you can also use ASP or other backend as long as you can run VFP code with this class).

The code to do this is very minimal. Basically you set up an instance of the wwHTTPSQLServer object and configure a couple of options that determine how the request is handled and then pass the XML to the S_Execute() method, which runs the actual SQL command and returns an XML result:

FUNCTION HTTPSQL_wwDevRegistry()

* ** Create Data Object and call Server Side Execute method (wrapper for Process Method)
SET PROCEDURE TO wwHTTPSQLServer ADDITIVE
loData = CREATE("wwHTTPSQLServer_Demo")
loData.cConnectString = "server=(local);driver={SQL Server};database=wwDeveloper;pwd=sa;uid=;"
loData.cAllowedCommands = "select,execute,insert,update,delete,method,"

loData.S_Execute(Request.FormXML())  

* ** Return the output 
Response.ContentType = "text/xml"
Response.AddForceReload()

Response.Write( loData.cResponseXML )
ENDFUNC

The above is the minimal code required to set up the server side. Once this URL is configured it can then be accessed via the cServerUrl property in wwBusiness.

There is additional info on how to deal with server side configuration such as authentication and reusing SQL connections available at the How wwHTTPSQLServer works topic.

See also

Class wwHTTPSQL |

© West Wind Technologies, 1996-2019 • Updated: 02/12/19
Comment or report problem with topic