This section illustrates how to start a SQL Anywhere HTTP web server, create a web service, and access it from a web browser. It does not illustrate SQL Anywhere web service features, such as SOAP over HTTP support and application development, to a full extent. Many SQL Anywhere web service features are available that are beyond the scope of this guide.
Perform the following tasks to create a SQL Anywhere HTTP web server and HTTP web service:
Start the SQL Anywhere HTTP web server while loading a SQL Anywhere database.
Run the following command at a command prompt:
dbsrv16 -xs http(port=8082) "%SQLANYSAMP16%\demo.db"
Use the dbsrv16 command to start a database server that can be accessed on a network. Use the dbeng16 command to start a personal database server that can be accessed by the local host only.
The -xs http(port=8082) option instructs the server to listen for HTTP requests on port 8082. Use a different port number if a web server is already running on port 8082.
Use the CREATE SERVICE statement to create a web service that responds to incoming web browser requests.
Connect to the demo.db database using Interactive SQL by running the following command:
dbisql -c "dbf=%SQLANYSAMP16%\demo.db;uid=DBA;pwd=sql"
Create a new web service in the database.
Execute the following SQL statement in Interactive SQL:
CREATE SERVICE SampleWebService TYPE 'web-service-type-clause' AUTHORIZATION OFF USER DBA AS SELECT 'Hello world!';
Replace web-service-type-clause with the desired web service type. The HTML type clause is recommended for web browser compatibility. Other general HTTP web service type clauses include XML, RAW, and JSON.
The CREATE SERVICE statement creates the SampleWebService web service, which returns the result set of the SELECT statement. In this example, the statement returns "Hello world!"
The AUTHORIZATION OFF clause indicates that authorization is not required to access the web service.
The USER DBA statement indicates that the service statement should be run under the DBA login name.
The AS SELECT clause allows the service to select from a table or function, or view data directly. Use AS CALL as an alternative clause to call a stored procedure.
View the web service in a web browser.
On the computer running the SQL Anywhere HTTP web server, open a web browser, such as Internet Explorer or Firefox, and go to the following URL:
This URL directs your web browser to the HTTP web server on port 8082. SampleWebService prints "Hello world". The result set output is displayed in the format specified by the web-service-type-clause from step 2. For more information about how result sets are displayed in web browsers, see Web service types.
Discuss this page in DocCommentXchange.
|Copyright © 2014, SAP AG or an SAP affiliate company. - SAP Sybase SQL Anywhere 16.0|