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.
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.
"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);
?>
".$result."";
?>
salut j’ai developper une application et je voullais la transformer en un web service j’ai deja ecrire le soap serveur mais rien ne change c’est à dire le serveur n’est pas creer. je pense que le prbm est dans la librerie nusoap je ne trouve pas ou je doit la mettre svp aider moi c’est tres urgent.
merci d’avance.
Salut,
J’ai essayé ton exemple, mais il ne semble pas fonctionner !
Lorsque j’appelle le client, voici ce qu’il m’affiche :
Warning: SoapClient::SoapClient(http://127.0.0.1/phpWS.php) [function.SoapClient-SoapClient]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Service Error in /var/www/appelWS.php on line 14
Warning: SoapClient::SoapClient() [function.SoapClient-SoapClient]: I/O warning : failed to load external entity « http://127.0.0.1/phpWS.php » in /var/www/appelWS.php on line 14
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn’t load from ‘http://127.0.0.1/phpWS.php’ in /var/www/appelWS.php:14 Stack trace: #0 /var/www/appelWS.php(14): SoapClient->SoapClient(‘http://127.0.0….’) #1 {main} thrown in /var/www/appelWS.php on line 14
Aurais-tu une idée de ce dont il peut s’agir ?
Merci d’avance 🙂
Peux tu m’envoyer stp ton code sur ma boite mail (eric.wallet chez yahoo france).
Merci beaucoup
Eric
idem, même problème que cité au dessus :s
Article intéressant, cependant, nusoap a du mal a fonctionner avec le service web Google Api…
j’ai un serveur python service web
et j’essaye de me connecter a partir d’un client php
il me donne array comme resultat
aidez moi svp voici le code:
set_magic_quotes_runtime(0);
//WebService Client.
require_once(« ../SLPproject/include/nusoap/nusoap.php »);
// Set the parameters to send to the WebService
$parameters = array(« text »=>$_SESSION[‘texte’]);
// Set the WebService URL
$soapclient = new soapclient(« http://127.0.0.1:1111/ »);
// Call the WebService and store its result in $result.
$result = $soapclient->call(« check_spell »,$parameters);
echo $result;
slt
ce code ne fonctionne pas car l’initialisation de WSDL manque
il faut rajouter ce bout de code dans le soapserver pour initialiser le wsdl.
$server->configureWSDL(‘Appelwsdl’, ‘urn:Appelwsdl’);
$server->register(‘bonjour’, // method name
array(‘prenom’ => ‘xsd:string’,
‘file’ => ‘xsd:string’,
‘language’ => ‘xsd:string’), // input parameters
array(‘return’ => ‘xsd:string’), // output parameters
‘urn:bonjour’, // namespace
‘urn:bonjourwsdl#’, // soapaction
‘rpc’, // style
‘encoded’, // use
« documentation » // documentation
);
avec ca tt est OK!!!
Bonjour chez moi ça marche pas. j’ai une erreur qui dit :
Le type de contenu text/xml; charset=ISO-8859-1 du message de réponse ne correspond pas au type de contenu de la liaison (text/xml; charset=utf-8). Si vous utilisez un codeur personnalisé, vérifiez que la méthode IsContentTypeSupported est implémentée correctement. Les premiers 441 octets de la réponse étaient : « Hello fff ! ».
voici le code de mon service
set_magic_quotes_runtime(0);
// Soap Server.
require_once(‘nusoap/lib/nusoap.php’);
// Create the soap Object
$s = new soap_server;
// Register a method available for clients
$s->register(‘hello’);
$s->configureWSDL(‘Appelwsdl’, ‘urn:Appelwsdl’);
$s->register(‘hello’, // method name
array(‘name’ => ‘xsd:string’
), // input parameters
array(‘return’ => ‘xsd:string’), // output parameters
‘urn:hello’, // namespace
‘urn:hellowsdl#’, // soapaction
‘rpc’, // style
‘encoded’, // use
‘documentation’ // documentation
);
function hello($name){
$returnedString = « Hello « .$name. » ! »;
return $returnedString;
}
// Return the results.
$s->service($HTTP_RAW_POST_DATA);
Bonjour,
je vous conseille de faire un tour sur le site http://www.wsdltophp.com qui permet de générer une librairie PHP à l’image d’un WSDL pour appeler un Web Service SOAP.
bon courage