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 responsesRun the following command to create a SQL Anywhere database:
dbinit ftc_client |
Start the personal database client using the following command:
dbsrv12 ftc_client.db |
Connect to the database in Interactive SQL using the following command:
dbisql -c "UID=DBA;PWD=sql;SERVER=ftc_client" |
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'
AUTHORIZATION OFF
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.
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 )
BEGIN
DECLARE io_header LONG VARCHAR;
DECLARE in_header LONG VARCHAR;
DECLARE result LONG VARCHAR;
DECLARE err INTEGER;
DECLARE crsr CURSOR FOR
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>' ||
'</Authentication>';
SET in_header =
'<Session xmlns="SomeSession">' ||
'123456789' ||
'</Session>';
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()');
END; |
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">
<first>Susan</first>
<last>Hilton</last>
</userName></Authentication> |
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"
mustUnderstand="1">
<first>Susan</first>
<last>Hilton</last>
</Authentication> |
See also![]() |
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |