XML, SOAP, and multitier programming is amazing technology that make we can collaborate with other programmer building big size and complex application in multiplatforms. This technology make us more easy and more simple in complicated world.
This tutorial about connecting PHP with VB.NET using web services. Why I use VB.NET to explain web services in PHP? I just want to show one of function of web services, connecting multiplatform.
In php, we can use nusoap library to create web services. You can download this library at http://sourceforge.net/projects/nusoap/. In this tutorial use nusoap-0.7.3.
- Download nusoap library.
- Extract to web directory, example within C:\AppServ\www\test. Rename folder became "nusoap". So, you get structure like this:
- Now, we will create server function. Create "server.php" within C:\AppServ\www\test\nusoap. Enter following code:
<?
//call library
require_once ('lib/nusoap.php');
//using soap_server to create server object
$server = new soap_server;
//register a function that works on server
$server->register('hello');
// create the function
function hello($name)
{
if(!$name){
return new soap_fault('Client','','Put your name!');
}
$result = "Hello, ".$name;
return $result;
}
// create HTTP listener
$server->service($HTTP_RAW_POST_DATA);
exit();
?>
- Now, it is time to test. Point your browser to http://localhost/test/nusoap/server.php. If work, you will get like following screen:
- After create server, now we will test this server function. Create "client.php" at test/nusoap. Enter following code:
<?
require_once ('lib/nusoap.php');
//Give it value at parameter
$param = array( 'name' => 'Babablackship');
//Create object that referer a web services
$client = new soapclient('http://localhost:8048/test/nusoap/server.php');
//Call a function at server and send parameters too
$response = $client->call('hello',$param);
//Process result
if($client->fault)
{
echo "FAULT: <p>Code: (".$client->faultcode."</p>";
echo "String: ".$client->faultstring;
}
else
{
echo $response;
}
?>
Now, point your browser to http://localhost/test/nusoap/client.php. You should see:
You can change value of parameter at line 5. But if value is nothing, it raise error message.
Next tutorial, we will try to read the web services from VB.NET. Don't miss it!