The goal of this lesson is to set up a SQL Anywhere web server running a web service.
Prérequis
This lesson assumes that you have the roles and privileges listed in the Privileges section at the start of this tutorial: Tutorial: Create a web server and access it from a web client.
Create a SQL Anywhere database that will be used to contain web service definitions.
dbinit -dba DBA,sql echo |
Start a network database server using this database. This server will act as a web server.
dbsrv16 -xs http(port=8082) -n echo echo.db |
The HTTP web server is set to listen on port 8082 for requests. Use a different port number if 8082 is disallowed on your network.
Connect to the database server with Interactive SQL.
dbisql -c "UID=DBA;PWD=sql;SERVER=echo" |
Create a new web service to accept incoming requests.
CREATE SERVICE EchoService TYPE 'RAW' AUTHORIZATION OFF SECURE OFF USER DBA AS CALL Echo(); |
This statement creates a new service named EchoService that calls a stored procedure named Echo when a web client sends a request to the service. It generates an HTTP response body without any formatting (RAW) for the web client. If you logged in with a different user ID, then the USER DBA clause must be changed to reflect your user ID.
Create the Echo procedure to handle incoming requests.
CREATE OR REPLACE PROCEDURE Echo() BEGIN DECLARE request_body LONG VARCHAR; DECLARE request_mimetype LONG VARCHAR; SET request_mimetype = http_header( 'Content-Type' ); SET request_body = isnull( http_variable('text'), http_variable('body') ); IF request_body IS NULL THEN CALL sa_set_http_header('Content-Type', 'text/plain' ); SELECT 'failed' ELSE CALL sa_set_http_header('Content-Type', request_mimetype ); SELECT request_body; END IF; END |
This procedure formats the Content-Type header and the body of the response that is sent to the web client.
![]() |
Discuter à propos de cette page dans DocCommentXchange.
|
Copyright © 2013, SAP AG ou société affiliée SAP - SAP Sybase SQL Anywhere 16.0 |