Showing posts with label Hello World. Show all posts
Showing posts with label Hello World. Show all posts

Hello World Clients with PHP

Tuesday, January 29, 2008

Yesterday I gave you the sources for the services. Here are the Web service clients.

With SOAP Extension:
<?php   
$client = new SoapClient(null, array('location' => "http://localhost:9090/soap_ext/hw_service.php",
'uri' => "http://test-uri/"));
$result =  $client->__soapCall('hello', array('name' => 'Sam'));
printf($result);
?>

With NuSOAP:
<?php
require_once('../lib/nusoap.php');
$client = new soapclient('http://localhost:9090/nusoap-0.7.3/samples/hw_service.php');
$result = $client->call('hello', array('name' => 'Sam'));
printf($result);
?>

With WSF/PHP:
<?php   
$reqestPayloadString = <<<XML
<hello>
<name>Sam</name>
</hello>

XML;
$client = new WSClient(array("to" => "http://localhost:9090/tutorial/hello/hw_service.php"));   
$response = $client->request($reqestPayloadString);   
$simplexml = new SimpleXMLElement($response->str);
$result = $simplexml->return[0];   
printf($result);   
?>  

Hello World Service with PHP SOAP Extension, NuSOAP and WSF/PHP

Monday, January 28, 2008

With SOAP extension:
<?php

function
hello($param) {
$retval = 'Hello, '.$param;
return $retval;
}

$server = new SoapServer(null, array('uri' => "http://test-uri/"));
$server->addFunction('hello');
$server->handle();
?>

With NuSOAP:
<?php
require_once('../lib/nusoap.php');

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

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

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

With WSF/PHP:
<?php   

function
hello($message) {

$simplexml = new SimpleXMLElement($message->str);
$name = $simplexml->name[0];

$responsePayloadString = <<<XML
<helloResponse>
<return>Hello, $name</return>
</helloResponse>

XML;

return
$responsePayloadString;
}

$service
= new WSService(array("operations" => array("hello")));
$service->reply();
?>