This quick start guide illustrates how to use SQL Anywhere as a web client application to connect to a SQL Anywhere HTTP server and access a general HTTP web service. It does not illustrate SQL Anywhere web client capabilities to a full extent. Many SQL Anywhere web client features are available that are beyond the scope of this guide.
The following tasks are performed:
Create and start a SQL Anywhere web client.
Create a procedure that connects to a web service on an HTTP server.
Perform operations on the result set sent by the HTTP server.
You can develop SQL Anywhere web client applications that connect to any type of online web server, but this guide assumes that you have started a local SQL Anywhere HTTP server on port 8082 and want to connect to a web service named SampleWebService, created with the following SQL script:
CREATE SERVICE SampleWebService TYPE 'HTML' USER DBA AUTHORIZATION OFF AS CALL sp_echo(:i, :f, :s); CREATE PROCEDURE sp_echo(i INTEGER, f REAL, s LONG VARCHAR ) RESULT( ret_i INTEGER, ret_f REAL, ret_s LONG VARCHAR ) BEGIN SELECT i, f, s; END; |
For more information about setting up a quick HTTP server, see Quick start guide to using SQL Anywhere as an HTTP web server.
Run the following command to create a SQL Anywhere client database if one does not already exist:
dbinit client-database-name |
Replace client-database-name with a new name for your client database.
Run the following command to start the client database:
dbsrv12 client-database-name.db |
Run the following command to connect to the client database through Interactive SQL:
dbisql -c "UID=DBA;PWD=sql;SERVER=client-database-name" |
Create a new client procedure that connects to the SampleWebService web service using the following SQL script:
CREATE PROCEDURE client_echo( f REAL, i INTEGER, s VARCHAR(16), x VARCHAR(16) ) URL 'http://localhost:8082/SampleWebService' TYPE 'HTTP:POST' HEADER 'User-Agent:SATest'; |
Run the following SQL script to call the client procedure and send an HTTP request to the web server:
CALL client_echo(3.14, 9, 's varchar', 'x varchar'); |
The output displayed in Interactive SQL should be similar to the following output:
Attribute | Value | ||
---|---|---|---|
Status | HTTP/1.1 200 OK | ||
Body |
|
||
Date | Wed, 09 Jun 2010 21:55:01 GMT | ||
Connection | close | ||
Expires | Wed, 09 Jun 2010 21:55:01 GMT | ||
Content-Type | text/html; charset=windows-1252 | ||
Server | SQLAnywhere/12.0.0 |
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |