WebServices NuSOAP - MySql

Résolu
Johandev35 Messages postés 20 Date d'inscription vendredi 15 décembre 2006 Statut Membre Dernière intervention 7 janvier 2009 - 6 août 2008 à 15:18
Johandev35 Messages postés 20 Date d'inscription vendredi 15 décembre 2006 Statut Membre Dernière intervention 7 janvier 2009 - 8 août 2008 à 11:37
Bonjour,
Je développe des WebServices (Service et client) avec la librairie NuSoap.
Pour les web services basiques tout marche bien, mais j'ai besoin de faire quelque chose de plus évolué et la je rencontre des difficultés.

En fait j'ai mon service, qui récupère un identifiant : $id
Et ma fonction va chercher dans ma base de données, les informations correspondant a cet ID.
Je met donc ces informations dans un tableau que je retourne a mon client.
Mais je n'arrive pas a exploiter ce tableau coté client.
Voici mon code coté service :
<?php
//connexion a la base de donnée déja effectué

//ma fonction
function getInfoClient($id) {
    $rq_infos = mysql_query("SELECT * FROM CLIENTS WHERE ID= $id");
    while($INFOS = mysql_fetch_array($rq_infos)){
    $tab_client = array();
    $nom_ = $INFOS['NOM'];
    $tab_client[]=$nom_;
   
    $prenom = $INFOS['PRENOM'];
    $tab_client[]=$prenom;
   
    $adresse = $INFOS['ADRESSE'];
    $tab_client[]=$adresse;
   
    $cp = $INFOS['CP'];
    $tab_client[]=$cp;
   
    $ville = $INFOS['VILLE'];
    $tab_client[]=$ville;
    }
    return $tab_client;
}

// Création du service
$server = new soap_server;

// Initialize WSDL support
$server->configureWSDL("Service", 'http://localhost/Service.php');

//define complex types for returned array of client information
$server->wsdl->addComplexType(
    'client',
    'complexType',
    'struct',
    'all',
    '',
    array(
        'nom' => array('name'=>'nom','type'=>'xsd:string'),
        'adresse' => array('name'=>'adresse','type'=>'xsd:string'),
        'cp' => array('name'=>'cp','type'=>'xsd:string'),
        'ville' => array('name'=>'ville','type'=>'xsd:string')
       )
);

$server->wsdl->addComplexType(
  'clients',
  'complexType',
  'array',
  '',
  'SOAP-ENC:Array',
  array(),
  array(
    array('ref' => 'SOAP-ENC:arrayType',
         'wsdl:arrayType' => 'tns:client[]')
  ),
  'tns:client'
);

// Enregistrement de la méthode
$server->register('getInfoClient',                    // method name
  array('id' => 'xsd:string'),          // input parameters
  array('return' => 'tns:client'),    // output parameters
  'http://localhost/Service',                  // namespace (espace de nommage unique)
  'http://localhost/Service.php#getInfoClient',     // soapaction (fonction)
  'rpc',                                    // style
  'encoded',                                // use
  'Infos client'        // documentation
);

// Invoque le service
$requete_HTTP_brute = (isset($HTTP_RAW_POST_DATA)?$HTTP_RAW_POST_DATA:'');
$server->service($requete_HTTP_brute);
?>

Et du coté de mon client je fais quelque chose comme ça :

<?php
 
// Inclusion de la librairie NuSOAP
require_once("./lib/nusoap.php");
 
$client = new soapclient('http://127.0.0.1/service.php');

// Appel de la méthode getInfoClient du service
$responseinfo = $client->call('getInfoClient',$param);

$nb = count($responseinfo);

for ($i = 0; $i<$nb; $i++)
{
echo $responseinfo[$i];
echo " ";
}
?>

Mais bien évidemment ça ne marche pas, sinon je n'aurais pas posté ce message :)

Si quelqu'un peut m'éclairer sur les erreurs éventuelles de mon code.
Je vous remercie !
Bonne journée !

2 réponses

Johandev35 Messages postés 20 Date d'inscription vendredi 15 décembre 2006 Statut Membre Dernière intervention 7 janvier 2009
8 août 2008 à 11:37
j'ai trouvé il faut juste enlever :

$server->wsdl->addComplexType(
  'clients',
  'complexType',
  'array',
  '',
  'SOAP-ENC:Array',
  array(),
  array(
    array('ref' => 'SOAP-ENC:arrayType',
         'wsdl:arrayType' => 'tns:client[]')
  ),
  'tns:client'
);
3
Johandev35 Messages postés 20 Date d'inscription vendredi 15 décembre 2006 Statut Membre Dernière intervention 7 janvier 2009
6 août 2008 à 15:20
J'ai oublié, coté client la variable $param :

$param = array('id'=>'1');

Merci
0
Rejoignez-nous