Topic 7a: Approaches to Web Services

Earliest approaches to networked applications

Earliest approaches did not involve XML or HTTP at all. Instead, client and server applications exchanged binary (non XML) data using custom (non HTTP) protocols: examples include CORBA, RMI (Sun), DCOM (Microsoft).

The philosophy was very much to develop distributed applications in the same manner as standard programs: the clients for these applications were typically standalone programs, rather than web applications, such as a Visual Basic or Java desktop application which needed to communicate with a remote database over the network. Therefore, non-network programmers felt relatively "at home" with these technologies.

The arrival of the true Web Service (XML over HTTP)

The arrival of XML as a data format led to the development of distributed approaches which exchanged XML, rather than binary data. Furthermore, the XML was sent using the standard protocol of the web, HTTP, delivered over port 80

So why XML over HTTP?

Remote Procedure Call Methods (XML-RPC and SOAP)

The first XML/HTTP-based approach we will look at is the Remote Procedure Call (RPC) approach. RPC-based web services share similarities with CORBA and the like in that they seek to allow the developer to develop the application in the same manner as a non-networked application. The basic unit is the function (also known as method or procedure); when you want to call the web service, you call a function much like you would in a regular program

The Web Service specifies a list of functions which clients may call over the net

Example of the RPC approach

If HitTastic! developed an RPC-based Web Service, it might offer a list of functions such as:

Each client could then call any one of these functions, depending on what they wanted to do.

Here is an example of code which calls an RPC web service. (note that this is a 'pseudolanguage' based on PHP: the code would not look exactly like this, but I've simplified it to illustrate the point)


$artist = $_POST["artist"]; 
$h = WebService('hittastic.com').getBiggestHit($artist);
echo "Biggest hit of $artist is: ";
echo  $h.title + " released in " + $h.year;

$songs = WebService('hittastic.com').searchForSongByArtist($artist);

for($i=0; $i < $songs.length; $i++)
{
    echo $songs[$i].title + ' came out in ' + $songs[$i].year;
}

Note how in the code we are calling the functions of the Web Service

Note also how the code illustrates the guiding principles of RPC-based approaches:

How is the data transported using RPC?

In RPC, not only the data itself (e.g. the artist), but also the type of the data (e.g. number or string), and the function we're calling, is encoded as XML and sent across the web This makes RPC messages both:

Here is an example of some data which would be transferred across the web using XML-RPC:

<methodCall>
    <methodName>findChartPosition</methodName>
    <params>
        <param>

            <value>
                <string>Oasis</string>
            </value>
        </param>
        <param>

            <value>
                <string>Wonderwall</string>
            </value>
        </param>
    </params>

</methodCall>
and here is an example of the result from the web service:
<methodResponse>
    <params>
        <param>
            <value>            
                <int>2</int>

            </value>
        </param>
    </params>
</methodResponse>

URL-based approaches

RPC based approaches distinguish different operations of the Web Service with different function calls. However, this is ignoring the fact that there is an existing Web feature that can be used to distinguish between different operations on the same server - namely the URL.

Why URL based approaches?

Plain old XML ("POX") over HTTP

POX is the most basic, and simplest, URL-based approach. Each web service operation is specified by a URL; you call the URL, using cURL for example, and get the XML back. For example, for HitTastic! :

hittastic.com/webservice.php?action=searchForSongByTitle&searchterm=Rock DJ
hittastic.com/webservice.php?action=searchForSongByArtist&searchterm=Beatles
hittastic.com/webservice.php?action=getWeekOfRelease&searchterm=Wonderwall,Oasis
hittastic.com/webservice.php?action=getBiggestHit&searchterm=Beatles

Notice how one script (webservice.php) is performing all the different Web Service operations. We tell the script which operation to perform using the action attribute. This is a common method of implementing "POX" web services, rather than having a separate script for each action. The script could then use if or switch statements to perform different actions.