Home arrow PHP arrow Page 5 - SOAP Servers and Web Services

SOAP Client and Server Interaction - PHP

In this conclusion to a five-part article series on Web Services, you'll learn how to create a SOAP server, add server functions, and more. This article is excerpted from chapter 20 of the book Beginning PHP and Oracle: From Novice to Professional, written by W. Jason Gilmore and Bob Bryla (Apress; ISBN: 1590597702).

  1. SOAP Servers and Web Services
  2. Creating a SOAP Server
  3. Adding a Server Function
  4. Adding Class Methods
  5. SOAP Client and Server Interaction
By: Apress Publishing
Rating: starstarstarstarstar / 3
August 10, 2010

print this article



Now that youíre familiar with the basic premises of using this extension to create both SOAP clients and servers, this section presents an example that simultaneously demonstrates both concepts. This SOAP service retrieves a famous quote from a particular boxer, and that boxerís last name is requested using the exposedgetQuote()method. Itís based on theboxing.wsdlfile shown earlier in Listing 20-5. Letís start with the server.

Creating the Boxing Server

The boxing server is simple but practical. Extending this to connect to a database server would be a trivial affair. Letís consider the code:

class boxingQuotes {
function getQuote($boxer) {
if ($boxer == "Tyson") {
$quote = "My main objective is to be professional
but to kill him. (2002)";
} elseif ($boxer == "Ali") {
$quote = "I am the greatest. (1962)";
} elseif ($boxer == "Foreman") {
$quote = "Generally when there's a lot of smoke,
there's just a whole lot more smoke. (1995)";
} else {
$quote = "Sorry, $boxer was not found.";
return $quote;

    $soapserver = new SoapServer("boxing.wsdl");


The client, introduced next, will consume this service.

Executing the Boxing Client

The boxing client consists of just two lines, the first instantiating the WSDL-enabled SoapClient() class, and the second executing the exposed method getQuote(), passing in the parameter "Ali":

$client = new SoapClient("boxing.wsdl");
echo $client->getQuote("Ali");

Executing the client produces the following output:

I am the greatest. (1962)


The promise of Web Services and other XML-based technologies has generated an incredible amount of work in this area, with progress regarding specifications and the announcement of new products and projects happening all the time. No doubt such efforts will continue, given the incredible potential that this concentration of technologies has to offer.

In the next chapter, youíll turn your attention to the security-minded strategies that developers should always keep at the forefront of their development processes.  

>>> More PHP Articles          >>> More By Apress Publishing

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates


Dev Shed Tutorial Topics: