Client applications can access IBM® data Web services by sending messages that use the SOAP/HTTP message protocol and three REST-like message protocols.
Prerequisite: Sending messages in the SOAP/HTTP protocol requires the installation of a SOAP engine on the Web server.
Client applications can perform database operations by sending requests to Web services that offer those operations. The requests are messages that are in all four of the following protocols:
For example, suppose that a client application requests a Web service to insert a row into the EMPLOYEE table of the DB2® SAMPLE database. The data types of the columns in the EMPLOYEE table are as follow:
| Name of column | Data type |
|---|---|
| EMPNO | INTEGER |
| LASTNAME | VARCHAR |
| FIRSTNME | VARCHAR |
| SKILLS | XML |
This table lists the values in the new row to insert:
| Name of column | Value |
|---|---|
| EMPNO | 200170 |
| LASTNAME | Yamamoto |
| FIRSTNME | Kiyoshi |
| SKILLS | <skills> <languages> <language name="Japanese" native="yes" level="excellent"/> <language name="English" native="no" level="good"/> </languages> <softskills> <skill name="team leadership" level="good"/> <skill name="presentation" level="medium"/> </softskills> </skills> |
The following operation is defined in the Web service:
INSERT INTO employee values (:empno, :lastname, :firstnme, :skills)
The following text is an example of the message that a client application could send using the SOAP/HTTP protocol.
POST /Sample/services/Sample HTTP/1.1
Host: localhost:8070
Content-Type: text/xml; charset=utf-8
Content-Length: 704
Accept: application/soap+xml, application/dime, multipart/related, text/*
User-Agent: IBM Web Services Explorer
Cache-Control: no-cache
Pragma: no-cache
SOAPAction: "http://www.example.org/insertEmployee"
Connection: close
<soapenv:Envelope xmlns:q0="http://www.example.org" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<q0:insertEmployee>
<empno>9225C03</empno>
<name>Doe</name>
<firstname>John</firstname>
<skills>
<skills>
<languages>
<language level="excellent" name="Japanese" native="yes"/>
<language level="good" name="English" native="no"/>
</languages>
<softskills>
<skill level="good" name="team leadership"/>
<skill level="medium" name="presentation"/>
</softskills>
</skills>
</skills>
</q0:insertEmployee>
</soapenv:Body>
</soapenv:Envelope>
The following text shows examples of the REST-like messages that a client application could send. The messages follow the REST format, but they do not behave like normal REST messages because they do not directly access a data entity. Instead, they perform functions. For example, messages in the GET format do not request a copy of a resource. Also, messages in the POST format do not necessarily add information to a resource. Instead, both GET and POST messages that clientapplications send are requests to perform operations on data in a database.
GET /Sample/RestEndpoint/Sample/insertEmployee?empno=9225C03&name;=Doe&firstname;=John&skills;=%3Cskills%3E%0D%0A%3Clanguages%3E%0D%0A++ %3Clanguage+level%3D%22very+good%22+name%3D%22Japanese%22+native%3D%22yes%22%2F%3E%0D%0A++%3Clanguage+level%3D%22good%22+name%3D%22English%22+ native%3D%22no%22%2F%3E%0D%0A%3C%2Flanguages%3E%0D%0A%3Csoftskills%3E%0D%0A++%3Cskill+level%3D%22good%22+name%3D%22team+leadership%22%2F%3E% 0D%0A++%3Cskill+level%3D%22medium%22+name%3D%22presentation%22%2F%3E%0D%0A%3C%2Fsoftskills%3E%0D%0A%3C%2Fskills%3E%0D%0A HTTP/1.1 User-Agent: Java/1.5.0 Host: localhost:8070 Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 Connection: keep-alive Content-type: application/x-www-form-urlencoded
http://server:port_number/Sample/RestEndpoint/Sample/insertEmployee?empno=9225C03&name;=Doe&firstname;=John&skills;=%3Cskills%3E%0D%0A%3Clanguages%3E%0D%0A++ %3Clanguage+level%3D%22very+good%22+name%3D%22Japanese%22+native%3D%22yes%22%2F%3E%0D%0A++%3Clanguage+level%3D%22good%22+name%3D%22English%22+ native%3D%22no%22%2F%3E%0D%0A%3C%2Flanguages%3E%0D%0A%3Csoftskills%3E%0D%0A++%3Cskill+level%3D%22good%22+name%3D%22team+leadership%22%2F%3E% 0D%0A++%3Cskill+level%3D%22medium%22+name%3D%22presentation%22%2F%3E%0D%0A%3C%2Fsoftskills%3E%0D%0A%3C%2Fskills%3E%0D%0AThe URL must use UTF-8 characters and conform to the RPC 2396 standard.
POST /Sample/RestEndpoint/Sample/insertEmployee HTTP/1.1 User-Agent: Java/1.5.0 Host: localhost:8070 Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 Connection: keep-alive Content-type: application/x-www-form-urlencoded Content-Length: 485 empno=9225C03&name;=Doe&firstname;=John&skills;=%3Cskills%3E%0D%0A%3Clanguages%3E%0D%0A++%3Clanguage+level%3D%22very+good%22+name%3D%22Japanese%22+ native%3D%22yes%22%2F%3E%0D%0A++%3Clanguage+level%3D%22good%22+name%3D%22English%22+native%3D%22no%22%2F%3E%0D%0A%3C%2Flanguages%3E%0D%0A%3Csof tskills%3E%0D%0A++%3Cskill+level%3D%22good%22+name%3D%22team+leadership%22%2F%3E%0D%0A++%3Cskill+level%3D%22medium%22+name%3D%22presentation%2 2%2F%3E%0D%0A%3C%2Fsoftskills%3E%0D%0A%3C%2Fskills%3E%0D%0A
POST /Sample/RestEndpoint/Sample/insertEmployee HTTP/1.1 Content-Type: text/xml; charset=utf-8 User-Agent: Michael Accept: text/xml, application/dime, multipart/related, text/* Content-Length: 467 Host: localhost:8070 Connection: keep-alive <q0:insertEmployee xmlns:q0="http://www.example.org"><empno>9225C03</empno><name>Doe</name><firstname>John</firstname><skills><skills> <languages> <language name="Japanese" native="yes" level="excellent"/> <language name="English" native="no" level="good"/> </languages> <softskills> <skill name="team leadership" level="good"/> <skill name="presentation" level="medium"/> </softskills> </skills></skills></q0:insertEmployee>
Support for DB2 XML Data Type in IBM Data Web Service Operations | Developing and Deploying IBM Data Web Services