Lesson 3: Sending a SOAP request and receiving a SOAP response

In this lesson, you call the wrapper procedure created in the previous lesson, which sends a SOAP request to the web server that you created in lesson one. For more information about setting up a web client to send the SOAP requests described in this lesson, see Lesson 2: Setting up a web client to send SOAP requests and receive SOAP responses.

 Send a SOAP request
  1. Connect to the client database in Interactive SQL if it is not already open from lesson two.

    dbisql -c "UID=DBA;PWD=sql;SERVER=ftc_client"
  2. Enable logging of SOAP requests and responses.

    Execute the following SQL statements in Interactive SQL:

    CALL sa_server_option('WebClientLogFile', 'soap.txt');
    CALL sa_server_option('WebClientLogging', 'ON');

    These calls allow you to examine the content of the SOAP request and response. The requests and responses are logged to a file called soap.txt.

  3. Call the wrapper procedure to send a SOAP request and receive the SOAP response.

    Execute the following SQL statement in Interactive SQL:

    CALL FahrenheitToCelsius(212);

    This call passes a Fahrenheit value of 212 to the FahrenheitToCelsius procedure, which passes the value along with two customized SOAP headers to the FToC procedure. Both client-side procedures are created in the previous lesson.

The FToC web service procedure sends the Fahrenheit value and the SOAP headers to the web server. The SOAP request contains the following.



<SOAP-ENV:Envelope
  xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:m="http://localhost:8082">
  <SOAP-ENV:Header>
    <Authentication xmlns="SecretAgent" mustUnderstand="1">
      <userName alias="99">
         <first>Susan</first>
         <last>Hilton</last>
      </userName>
    </Authentication>
    <Session xmlns="SomeSession">
      123456789
    </Session>
  </SOAP-ENV:Header>
  <SOAP-ENV:Body>
    <m:FtoCService>
      <m:temperature>212</m:temperature>
    </m:FtoCService>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

The FtoC procedure then receives the response from the web server which includes a result set based on the Fahrenheit value. The SOAP response contains the following.



<SOAP-ENV:Envelope 
  xmlns:xsd='http://www.w3.org/2001/XMLSchema' 
  xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' 
  xmlns:SOAP-ENV='http://schemas.xmlsoap.org/soap/envelope/' 
  xmlns:tns='http://localhost:8082'>
  <SOAP-ENV:Header>
    <Authentication xmlns="SecretAgent" alias="99" mustUnderstand="1">
      <first>Susan</first>
      <last>Hilton</last>
    </Authentication>
  </SOAP-ENV:Header> 
  <SOAP-ENV:Body>
    <tns:FtoCServiceResponse>
      <tns:FtoCServiceResult xsi:type='xsd:string'>
        &lt;tns:rowset xmlns:tns=&quot;http://localhost:8082/ftc&quot;&gt;&#x0A; 
        &lt;tns:row&gt;&#x0A;  
        &lt;tns:answer&gt;20
        &lt;/tns:answer&gt;&#x0A; 
        &lt;/tns:row&gt;&#x0A;
        &lt;/tns:rowset&gt;&#x0A;   
      </tns:FtoCServiceResult>
      <tns:sqlcode>0</tns:sqlcode>
    </tns:FtoCServiceResponse>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

The content of <SOAP-ENV:Header> is returned in inoutheader.

If you examine the SOAP response, you can see that the result set was encoded in the response by the FToCService web service. The result set is decoded and returned to the FahrenheitToCelsius procedure. The result set looks like the following when a Fahrenheit value of 212 is passed to the web server:

<tns:rowset xmlns:tns="http://localhost:8082/ftc"> 
  <tns:row>
    <tns:answer>100
    </tns:answer>
  </tns:row>
</tns:rowset>

The SELECT statement in the FahrenheitToCelsius procedure uses the OPENXML function to parse the SOAP response, extracting the Celsius value defined by the tns:answer structure.

The following result set is generated in Interactive SQL:

temperature Celsius
212 100
 See also