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

SQL Anywhere 12.0.0 (Français) » SQL Anywhere Server - Programming » HTTP web services » HTTP web service examples » Tutorial: Using SQL Anywhere to access a SOAP/DISH service


Lesson 2: Set up a web client database to send SOAP requests and receive SOAP responses

In this lesson, you set up a web client that sends SOAP requests and receives SOAP responses. This lesson assumes that you have set up a web server database as instructed in the previous lesson. For more information about setting up a database server to receive the SOAP requests from the client described in this lesson, see Lesson 1: Set up a web server database to receive SOAP requests and send SOAP responses.


This lesson contains several references to localhost. Use the IP address of the server database from lesson 1 instead of localhost if you are not running the web client on the same computer as the server database.

 ♦  To set up a database client for sending SOAP requests and receiving SOAP responses
  1. Run the following command to create a SQL Anywhere database:

    dbinit ftc_client
  2. Start the personal database client using the following command:

    dbsrv12 ftc_client.db
  3. Connect to the database in Interactive SQL using the following command:

    dbisql -c "UID=DBA;PWD=sql;SERVER=ftc_client"
  4. Create a new stored procedure to send SOAP requests to a DISH service.

    Run the following SQL script in Interactive SQL:

    CREATE SERVICE soap_endpoint 
        TYPE 'DISH'
        SECURE OFF
        USER DBA;
    CREATE PROCEDURE FtoC( temperature FLOAT )
        URL 'http://localhost:8082/soap_endpoint'
        SET 'SOAP(OP=FtoCService)'
        TYPE 'SOAP:DOC';

    The http://localhost:8082/soap_endpoint string in the URL clause indicates that the database server runs on localhost and listens on port 8082. The desired DISH web service is named soap_endpoint, which servers as a SOAP endpoint.

  5. Create a wrapper procedure that builds a SOAP header, passes it to the FtoC procedure, and processes server responses.

    Run the following SQL script in Interactive SQL:

    CREATE PROCEDURE FahrenheitToCelsius( temperature FLOAT )
      DECLARE io_header LONG VARCHAR;
      DECLARE in_header LONG VARCHAR;
        CALL FtoC( temperature, io_header, in_header );
      SET io_header =
        '<Authentication xmlns="SecretAgent" ' ||
        'mustUnderstand="1">' ||
        '<userName alias="99">' ||
        '<first>Susan</first><last>Hilton</last>' ||
        '</userName>' ||
      SET in_header =
        '<Session xmlns="SomeSession">' ||
        '123456789' ||
      MESSAGE 'send, soapheader=' || io_header || in_header;
      OPEN crsr;
      FETCH crsr INTO result, err;
      CLOSE crsr;
      MESSAGE 'receive, soapheader=' || io_header;
      SELECT temperature, Celsius
          FROM OPENXML(result, '//tns:answer', 1, result)
          WITH ("Celsius" FLOAT 'text()');

    The first SET statement specifies the following XML representation of a SOAP header to inform the web server of user credentials:

    <Authentication xmlns="SecretAgent" mustUnderstand="1">
        <userName alias="99">

    The second SET statement sets the following XML representation of a SOAP header to track the client session ID:

    <Session xmlns="SomeSession">123456789</Session>

    The OPEN statement passes the following XML representation of a SOAP request to the web service procedure:

    <Authentication xmlns="SecretAgent" alias="99" 
 See also