GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Saturday, April 16, 2011

PHP - The First Web Services

This is my first web service I try to do that successfully executed:
index.php
<?php
require_once "nusoap.php";

$server = new soap_server;
$server->register('hello');

function hello($name){
    return 'Hello, '.$name.' From Soap Server';
}

$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : '';
$server->service($HTTP_RAW_POST_DATA);
?>

While the client code is:
<?php
require_once 'nusoap.php';

$client = new SoapClient(
    null,
    array(
        'location' => 'http://localhost/index.php',
        'uri' => 'http://localhost:80',
        'soap_version' => '0.9.5',
    )
);

$result = $client->hello('Barack Obama');
print_r($result);
?>
Share/Bookmark

2 comments:

  1. where to get the nusoap.php file from. what is in it?

    ReplyDelete
  2. To get nusoap, just googling it, and you will get link to sourceforge.net
    But i recommmend to use Zend SOAP. It makes very productive and the most is its easiness. Try to check my post in Zend tags.

    ReplyDelete