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

SAP Sybase SQL Anywhere 16.0 » SQL Anywhere Server - Programming » HTTP web services » HTTP web service examples » Tutorial: Using SQL Anywhere to access a SOAP/DISH service


Lesson 2: Setting up a web client 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 as instructed in the previous lesson. See Lesson 1: Setting up a web server to receive SOAP requests and send SOAP responses.

This lesson assumes that you have the roles and privileges listed in the Privileges section at the start of this tutorial: Tutorial: Using SQL Anywhere to access a SOAP/DISH service.

Context and remarks

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

  1. Run the following command to create a SQL Anywhere database:

    dbinit -dba DBA,sql ftc_client
  2. Start the database client using the following command:

    dbsrv16 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.

    Execute the following SQL statement in Interactive SQL:

        INOUT inoutheader LONG VARCHAR,
        IN inheader LONG VARCHAR )
      URL 'http://localhost:8082/soap_endpoint'
      SET 'SOAP(OP=FtoCService)'
      SOAPHEADER '!inoutheader!inheader';

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

    The SET clause specifies the name of the SOAP operation or service FtoCService that is to be called.

    The default format used when making a web service request is 'SOAP:RPC'. The format chosen in this example is 'SOAP:DOC', which is similar to 'SOAP:RPC' but allows for a richer set of data types. SOAP requests are always sent as XML documents. The mechanism for sending SOAP requests is 'HTTP:POST'.

    The substitution variables (inoutheader, inheader) in a web service client procedure like FtoC must be alpha-numeric. If the web service client is declared as a function, all its parameters are IN mode only (they cannot be assigned by the called function). Therefore, OPENXML or other string functions would have to be used to extract the SOAP response header information.

  5. Create a wrapper procedure that builds two special SOAP request header entries, passes them to the FtoC procedure, and processes server responses.

    Execute the following SQL statements in Interactive SQL:

    CREATE OR REPLACE PROCEDURE FahrenheitToCelsius( Fahrenheit FLOAT )
      DECLARE io_header LONG VARCHAR;
      DECLARE in_header LONG VARCHAR;
        CALL FtoC( Fahrenheit, 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 Fahrenheit, Celsius
          FROM OPENXML(result, '//tns:answer', 1, result)
          WITH ("Celsius" FLOAT 'text()');

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

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

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

    <Session xmlns="SomeSession">123456789</Session>
  6. The OPEN statement causes the FtoC procedure to be called which sends a SOAP request to the web server and then processes the response from the web server. The response includes a header which is returned in inoutheader.


At this point, you now have a client that can send SOAP requests to the web server and receive SOAP responses from the web server.


In the next lesson, you send a SOAP request to the web server and examine the SOAP response. Proceed to Lesson 3: Sending a SOAP request and receiving a SOAP response.

 See also