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);
?> |
Partager