Quick start guide to using SQL Anywhere as an HTTP web server

This quick start guide 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.

The following tasks are performed:

  • Start a SQL Anywhere HTTP web server database

  • Create a general HTTP web service

  • View the web service in a web browser

 To create a SQL Anywhere HTTP web server and a general HTTP web service
  1. Start the SQL Anywhere HTTP web server while loading a SQL Anywhere database.

    Run the following command at the command prompt:

    dbeng12 -xs http(port=8082) samples-dir\demo.db
    Note

    Use the dbeng12 command to start a personal database server that can only be accessed by the local host. Use the dbsrv12 command to start a network database server instead.

    Replace samples-dir with the location of your samples directory. 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.

    For more information about starting an HTTP web server, see Starting an HTTP web server.

  2. Use the CREATE SERVICE statement to create a web service that responds to incoming web browser requests.

    1. Connect to the demo.db database using Interactive SQL.

      Run the following command from the samples-dir directory:

      dbisql -c "dbf=samples-dir\demo.db;uid=DBA;pwd=sql"
    2. Create a new web service in the database.

      Run the following SQL script 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. You can use the SOAP and DISH type clauses for creating a SOAP over HTTP web service but these types are not compatible with the above statement. For more information about supported web service types, see Choosing a web service type.

      The CREATE SERVICE statement creates the SampleWebService web service, which returns the result set of the SELECT SQL statement. In this example, the script 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.

      For more information about the CREATE SERVICE statement and these clauses, see CREATE SERVICE statement.

  3. 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:

    http://localhost:8082/demo/SampleWebService

    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 Choosing a web service type.

 Other sample resources