La librairie nusoap permet la création en PHP de webservice basés sur SOAP. Se baser sur un protocole tel que SOAP pour votre webservice, permet de mettre en place simplement la communication entre des applications .net / java / perl … et PHP.
Voici un exemple de serveur SOAP basic en PHP.
<?php set_magic_quotes_runtime(0); // Soap Server. require_once('../../lib/php/soap/nusoap.php'); // Create the soap Object $s = new soap_server; // Register a method available for clients $s->register('hello'); function hello($name){ $returnedString = "Hello ".$name." !"; return $returnedString; } // Return the results. $s->service($HTTP_RAW_POST_DATA); ?>
Maintenant, faisons une petite page interrogeant notre webservice.
<?php set_magic_quotes_runtime(0); //WebService Client. require_once("../../lib/php/soap/nusoap.php"); // Set the parameters to send to the WebService $parameters = array("name"=>"tellaw"); // Set the WebService URL $soapclient = new soapclient("http://www.myWebSite.com/ServeurSoap.php"); // Call the WebService and store its result in $result. $result = $soapclient->call("hello",$parameters); ?> <html> <head> <title>Création d'un webservice en php utilisant SOAP</title> </head> <body> <center> <h4> <?php echo "<b>".$result."</b>"; ?> </h4> </center> </body> </html>






Espace de communautaire - postez vos commentaires