Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 12.0.1 » SQL Anywhere Server - Programming » HTTP web services » SQL Anywhere as an HTTP web server


Quick start to using SQL Anywhere as an HTTP web server

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.

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

 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 a command prompt:

    dbeng12 -xs http(port=8082) "%SQLANYSAMP12%\demo.db"

    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.

    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.

  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 by running the following command:

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

      Execute the following SQL statement in Interactive SQL:

      CREATE SERVICE SampleWebService
          TYPE 'web-service-type-clause'
          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.

  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:


    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.

 Other sample resources
 See also