Consuming the Web Service

Now that we’ve created our web service (at the location, we can create a client script to consume the web service.

For this, we are going to use Zend_Soap_Client class. You could use PHP’s built-in SoapClient class (or even use a programming language other than PHP), but since this is a series on the Zend Framework we’ll use the Zend_Soap_Client class.

Consuming the service is simply a matter of instantiating Zend_Soap_Client with the URL of the WSDL file ( as the only argument, then calling the functions from the PHP class we created earlier as if they were local function calls.

Note: There are several options that can be customised when instantiating Zend_Soap_Client, but to keep things simple I won’t cover them here. You can read more at

Listing 5 shows how we make use of the web service calls. The PHP script can live on a completely different web server and URL to your server. After all, that is the point of web services!

Listing 5 Instantiating the Zend_Soap_Client class and making calls to the web service (client.php)
    $url = '';
    $client = new Zend_Soap_Client($url);
    echo sprintf('Server Timestamp: %s', $client->getDate());
    echo "<br />\n";
    echo $client->getAgeString('Quentin', 28);

In this code you will see we call $client->getDate() and $client->getAgeString(). When these functions are called, internally Zend_Soap_Client is communicating with the SOAP server specified in $url.

While this is a somewhat simplified implementation, it works, and it should demonstrate how to implement both the server and client aspects of a SOAP web service!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s