Looking for Web Services
Finally, we are interested in searching for a Web service in a UBR. Unfortunately, the SOAP module of PHP does not offer this functionality. However, a PEAR package exists, called UDDI, that does this job. The package's home page is http://pear.php.net/package/UDDI, shown in Figure 18.6. As of the time of writing, the package is still in its alpha stage, so the API is not fixed yet; however, the chances are good that it will not change significantly. To install it, you have to look up the most current version number of the package and then install it using the following command:
pear install UDDI-version
Figure 18.6. The homepage of PEAR::UDDI.
For instance, to install UDDI 0.2.0alpha3, type
pear install UDDI-0.2.0alpha3
PEAR::UDDI supports the full UDDI 2.0 Inquiry API. Listing 18.6 queries the IBM test UBR for all Web services that contain the string guid, and Figure 18.7 shows the associated result. This uses the fact that the names of all suitable services are between <name> and </name>, so the regular expression /<name.*?>(.*)<\/name>/ returns the name itself (note that *? is a nongreedy qualifier so that we get a name and not everything between the first <name> and the last </name> at once).
Listing 18.6. Querying the IBM UBR for guid Services
<?php require_once 'UDDI.php'; $uddi = new UDDI('IBM', 2); $options = array( 'findQualifiers' => 'sortByNameAsc,sortByDateDesc', 'maxRows' => 25, 'name' => '%guid%'); $result = $uddi->query('find_business', $options); preg_match_all('/<name.*?>(.*)<\/name>/', $result, $hits); echo '<ul><li>' . implode('</li><li>', $hits) . '</li></ul>'; ?>
Figure 18.7. All services with "guid" in the name.