Supported message protocols
Client applications can access Web services by sending messages that use the SOAP/HTTP or SOAP/JMS protocols, or three REST-like message protocols.
Client applications can perform database operations by sending requests to Web services that offer those operations. The requests are messages that are in one of the following six protocols:
- SOAP/HTTP
- SOAP/JMS (WebSphere® Application Server only)
- REST-like HTTP GET (url-encoded)
- REST-like HTTP POST (url-encoded)
- REST-like HTTP POST (text/xml)
- REST-like HTTP POST (json)
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:
Table 1. The columns of the EMPLOYEE table Name of column Data type EMPNO integer LASTNAME varchar FIRSTNME varchar SKILLS XML This table lists the values in the new row to insert:
Table 2. The values to insert into the EMPLOYEE table 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>This is the operation that is defined in the Web service:
INSERT INTO employee values (:empno, :lastname, :firstnme, :skills)
Example input message that uses the SOAP/HTTP message protocol
Here 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>200170</empno> <name>Yamamoto</name> <firstname>Kiyoshi</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>
Example input messages that use the REST-like message protocols
Here are 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 client applications send are requests to perform operations on data in a database.
In REST-like messages, null values are treated differently for XML-based requests and non-XML requests. In XML-based requests, null values are represented by adding xsi:nil="true" to the parameter element. In non-XML requests, null values are represented as absent; that is, the parameter name does not appear in the parameter or value list.
- Example input message that uses REST-like HTTP GET (url-encoded)
GET /Sample/RestEndpoint/Sample/insertEmployee?empno=200170&name;=Yamamoto&firstname;=Kiyoshi&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- Example input message that uses REST-like HTTP POST (url-encoded)
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=200170&name;=Yamamoto&firstname;=Kiyoshi&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- Example input message that uses REST-like HTTP POST (text/xml)
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>200170</empno><name>Yamamoto</name><firstname>Kiyoshi</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>- Example input message that uses REST-like HTTP POST (json)
POST /Project1WebService1/rest/WebService1/insertEmployee HTTP/1.1 Host: localhost:8000 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Connection: keep-alive Content-Type: application/json;charset=utf-8 Content-Length: 395 {"insertEmployee":{"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>"}}
Related concepts
Support for the DB2 native XML data type in Web service operations
Related tasks
Developing and deploying Web services
Testing a Web service with the Data Web Services Test Client