SOAP or Simple Object Access Protocol is simple and versatile solution for making calls from programs running on MachineA to programs running on MachineB. SOAP allows the creation of Web Services, which are standardized computing resources that take input from across a network and respond in an advertised way. SOAP is a specification for extensible markup language (XML) messages that travel between endpoints. In terms of networking, SOAP messages travel on top of HTTP or simple mail transport protocol (SMTP). A function can be exposed through a SOAP server, meaning it can accept SOAP messages from elsewhere on the network and return results in a response. These functions, when exposed, become Web Services -- computing resources that may be accessed over the network via web protocols.
In this lab we will be create and register a simple SOAP server with several functions exposed as Web Services. Then we will create a simple SOAP client that will use the new Web Services.
The instructions on this page will show you how to:
Note: You must have completed the Google lab before completing this lab!
We will create a simple SOAP server with NuSOAP classes. If you have not already installed NuSOAP, please read the instructions from the Google lab.
Using Notepad2 or your favorite editor, create a PHP file called soapserver.php.
<?php
require_once('nusoap/lib/nusoap.php');
$s = new soap_server;
$s->register('hello');
$s->service($HTTP_RAW_POST_DATA);
Next we will create the simple function that we have registered.
function hello($name) {
return "Czesc $name !
(Czesc is 'hi' in Polish)";
}
?>
Now that we have created our SOAP server, we need to create a SOAP client that uses our registered Web Service.
<html> <head><title>Simple Hello Soap Client</title></head> <body> <h2>Simple Hello Soap Client</h2> <p>Enter your name and the program will say hello.</p> <form action="<?PHP $PHP_SELF; ?>" method="get"> <br />Your name is: <input type="text" name="name" /> </form> </body> </html>
Now, we'll create a new soap client and provide as parameters
an associative array with a key label 'name' and a value from the form. Next the
registered function 'hello' is called.
<?php
require_once('./nusoap/lib/nusoap.php');
$soapclient = new soapclient("http://localhost/php_examples/soapserver.php");
$parameters = array('name' => $_GET['name']);
echo $soapclient->call('hello', $parameters);
?>
We don't want to run this SOAP client everytime the page is load, only every
time a user types something into the text box. Lets add an if statement to check if
the form variable $_GET['name'] is empty or not.
<?php
if ($_GET['name'] != "") {
require_once('./nusoap/lib/nusoap.php');
$soapclient = new soapclient("http://students.washington.edu/suzka/classes/in\
fo344/php/soapserver.php");
$parameters = array('name' => $_GET['name']);
echo $soapclient->call('hello', $parameters);
} else {
?>
<form action="<?PHP $_SERVER['PHPSELF'] ?>" method="get">
<br />Your name is: <input type="text" name="name" />
</form>
<?php
}
?>
Your new form should look something like this:

You should try to run your new SOAP client now! When it works you should see something like this:

Create your own function and register it as a SOAP service. Create a simple SOAP client that queries it and displays the response.