Bonjour,

Cela fait une semaine que je débute avec les webservices, d'aprés ce que j'ai lu, Nusoap et trés bien pour commencer.

Aprés avoir effectuer des "hello world", j'ai décider de travailler sur une base de donnée.

Le soucis, aprés avoir effectuer ma requête en "SELECT *" sur une table, je ne sais la traité ni coter serveur ni coter client.

Je sais qu'il faut intégrer un complextype, mais je ne suis pas sur non plus de la syntaxe à utiliser.

Voici le code pour le serveur:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
 
<?php 
 
    //includes nusoap classes 
    require('lib/nusoap.php'); 
 
    //create server 
    $server = new soap_server(); 
 
    //wsdl generation 
    $server->debug_flag=false; 
    $server->configureWSDL('Weather', 'http://weather.org/Weather'); 
    $server->wsdl->schemaTargetNamespace = 'http://weather.org/Weather'; 
 
    //add complex type 
    $server->wsdl->addComplexType( 
        'produitData', 
        'complexType', 
        'struct', 
        'all', 
        '', 
        array( 
            'reference' => array('name'=>'reference', 'type'=>'xsd:string'),
			'constructeur' => array('name'=>'constructeur', 'type'=>'xsd:string'),
			'categorie' => array('name'=>'categorie', 'type'=>'xsd:string'),
			'date' => array('name'=>'date', 'type'=>'xsd:date '),
			'fich_tech' => array('name'=>'fich_tech', 'type'=>'xsd:string'),
			'nombre' => array('name'=>'nombre', 'type'=>'xsd:int')
			) 
    ); 
 
	$server->wsdl->addComplexType(
    	'arrproduitData',		//Name of Array
    	'complexType',					//Type Class (Complex)
    	'array',						//Php Type (Array)
    	'',								//Compistor??
    	'SOAP-ENC:Array',				//Restriction Base
    	array(),
    	array(
    		array('prod' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:produitData[]') //link back to complexType via namespace
    		),
    	'tns:produitData'
    );
 
 
    // register method 
    $server->register('getproduit', array( 
        'city' => 'xsd:string'),  
            array('return'=>'tns:produitData'),  
                'http://weather.org/Weather'); 
 
    // method code (get DB result) 
    function getproduit () {    
            $l_oDBlink   = @mysql_connect( 
                'localhost', 'user', 'pwd'); 
            $l_oDBresult = @mysql_db_query( 
                'table',  
                'SELECT * FROM T_produit'); 
 
            // simple error checking 
            if (!$l_oDBresult) { 
                return new soap_fault('Server', '', 'Internal server error.'); 
            } 
 
 
 
 
			while($r = mysql_fetch_array($l_oDBresult)) {
				$produit[] = array(
	 			'reference' => $r['reference'],
	 			'constructeur' => $r['constructeur'],
	 			'categorie' => $r['categorie'],
	 			'date' => $r['date'],
	 			'fiche_tech' => $r['fiche_tech'],
	 			'nombre' => $r['nombre']
				);
 
			}
            // return data 
            return $produit;    
 
 
      } 
 
    // pass incoming (posted) data 
    $server->service($HTTP_RAW_POST_DATA);
 
?>

et voici la page cliente:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
<?php     
           // includes nusoap classes 
        require('lib/nusoap.php'); 
 
        // set parameters and create client 
        $client  = new soapclient('http://10.22.204.252:5086/jonathan/webservice/webservice_bdd.php'); 
 
        // check for errors 
        if (!$client->getError()) { 
		$reponse = $client->call('getproduit'); 	
		$result=$reponse;
		$count = count($result);
 
		echo $result;
?>
 
 
					<table border='1' cellspacing='1'>
						<tr>
							<th>reference</th>
							<th>constructeur</th>
							<th>categorie</th>
							<th>date</th>
							<th>fiche technique</th>
							<th>nombre</th>
						</tr>
<?php
		for($i=0;$i<$count-1;$i++){
					$rowtype=($i%2)?"style='background:#88DAEB'":"style='background:#FFF'";
?>
						<tr <?php echo $rowtype; ?>>
							<td><?php echo $result[$i]['reference']?></td>
							<td><?php echo $result[$i]['constructeur']?></td>
							<td><?php echo $result[$i]['categorie']?></td>
							<td><?php echo $result[$i]['date']?></td>
							<td><?php echo $result[$i]['fiche_tech']?></td>
							<td><?php echo $result[$i]['nombre']?></td>
						</tr>
<?php
		}
?>
					</table>
<?php
	}	
?>
<style type="text/css">
	th{
		background:#007F99;
		color:#fff;
	}
</style>