PHP & SOAP

Résolu/Fermé
olfah Messages postés 15 Date d'inscription lundi 7 mars 2016 Statut Membre Dernière intervention 4 avril 2016 - 7 mars 2016 à 14:26
olfah Messages postés 15 Date d'inscription lundi 7 mars 2016 Statut Membre Dernière intervention 4 avril 2016 - 7 mars 2016 à 22:01
Bonjour,

Je suis débutante avec SOAP. J'ai crée un client et un serveur et j'aimerais bien faire deux fonctions une pour la récupération et autre pour l'insertion.

la fonction de récupération fonctionne correctement mais la fonction d'insertion ne marche pas.

serveur:
require_once ('lib/nusoap.php'); 
$server = new soap_server();
$server->configureWSDL('Test','urn:Test');

$server->soap_defencoding = 'utf-8';

$server->register('connection',array('ID' => 'xsd:int'),
array('return' =>'xsd:string'));
$server->register('insertUser',array('FirstName'=>'xsd:string','LastName' =>'xsd:string'),array('return' =>'xsd:string'));
//base de donnée
function connection($ID){
try {
$db=new PDO('mysql:host=localhost;dbname=service','root','');
foreach($db->query('select * from myusers where ID = '.$ID) as $row)
{
return $row['FirstName'];
break;
}
} catch (PDOException $e) {
print "Erreur !: " . $e->getMessage() . "<br/>";
die();
}

}
function insertUser($FirstName,$LastName){
try {
$db1=new PDO('mysql:host=localhost;dbname=service','root','');
$req=$db1->prepare('insert into myusers values(?,?)');

$FirstName=$_POST['nom'];
$LastName=$_POST['prenom'];

$req->bindParam(1,$FirstName);
$req->bindParam(2,$LastName);
$req->execute();
return "client ajouter";

}
catch (PDOException $e) {
print "Erreur !: " . $e->getMessage() . "<br/>";
die();
}
}


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

code client:
<?php
// Pull in the NuSOAP code
require_once('lib/nusoap.php');
// Create the client instance

$client = new nusoap_client('http://localhost/testc/server.php');
$result = $client->call('connection',array('ID' => 1));
echo $result;
if(isset($_POST['btn_ajt']))
{
$res=$client->call('insertUser',array('FirstName'=>$_POST['nom'],'LastName'=>$_POST['prenom']));
echo $res;
}
else
{
echo "
<form name='test' method='post' action='server.php'>
<table>

<tr><td>Nom</td><td><input type='text' name='nom'></td></tr>
<tr><td>Prenom</td><td><input type='text' name='prenom'></td></tr>
<tr><td><input type='submit' value='ajouter' name='btn_ajt'></td></tr>
</table>
</form>";
}


Merci d'avance
A voir également:

1 réponse

jordane45 Messages postés 38137 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
7 mars 2016 à 14:37
Bonjour,

là comme ça... je pense que l'erreur se trouve là :
Côté serveur tu écris :
	$FirstName=$_POST['nom'];
	$LastName=$_POST['prenom'];

mais côté client tu as mis :
$res=$client->call('insertUser',array('FirstName'=>$_POST['nom'],'LastName'=>$_POST['prenom']));

plus exactement :
array('FirstName'=>$_POST['nom'],'LastName'=>$_POST['prenom'])

Donc... tu envoies ... non plus "nom" et "prenom" ... mais .. "FirstName" et LastName"
0
olfah Messages postés 15 Date d'inscription lundi 7 mars 2016 Statut Membre Dernière intervention 4 avril 2016
7 mars 2016 à 14:45
Merci pour votre réponse
J'ai la corrigé mais l'ajout ne s'effectue pas..
0
jordane45 Messages postés 38137 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649 > olfah Messages postés 15 Date d'inscription lundi 7 mars 2016 Statut Membre Dernière intervention 4 avril 2016
7 mars 2016 à 14:49
Et que t'affiche ton echo $res; ?
0
olfah Messages postés 15 Date d'inscription lundi 7 mars 2016 Statut Membre Dernière intervention 4 avril 2016
7 mars 2016 à 14:52
rien n'est afficher
0
jordane45 Messages postés 38137 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024 4 649
7 mars 2016 à 14:59
A la place de tes :
print "Erreur !: " . $e->getMessage() . "<br/>";
    die();

mets donc un
return  "Erreur !: " . $e->getMessage() ;
0
olfah Messages postés 15 Date d'inscription lundi 7 mars 2016 Statut Membre Dernière intervention 4 avril 2016 > jordane45 Messages postés 38137 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 17 avril 2024
7 mars 2016 à 15:03
le message affiché :

This XML file does not appear to have any style information associated with it. The document tree is shown below.
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode xsi:type="xsd:string">SOAP-ENV:Client</faultcode>
<faultactor xsi:type="xsd:string"/>
<faultstring xsi:type="xsd:string">
Operation '' is not defined in the WSDL for this service
</faultstring>
<detail xsi:type="xsd:string"/>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
0