[PHP] Serveur de WebServices SOAP
juillet 19, 2010
A la demande général, je met le code de mon serveur de WebServices SOAP qui sert dans mon tutorial pour l’iPhone.
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 | <?php //On inclue les librairies include('nusoap.php'); include('database.php'); $serveur = new soap_server; //On configure le serveur $serveur->configureWSDL('Books', 'http://www.jkraft.fr/ws/serveur.php', 'http://www.jkraft.fr/ws/serveur.php?wsdl'); $server->wsdl->schemaTargetNamespace ='http://www.jkraft.fr/ws/serveur.php'; //On créer les schémas $serveur->wsdl->addComplexType( 'Contact', 'complexType', 'struct', 'all','', array( 'nom' => array('name' => 'nom', 'type' => 'xsd:string'), 'prenom' => array('name' => 'prenom', 'type' => 'xsd:string'), 'web' => array('name' => 'web', 'type' => 'xsd:string'), 'tel' => array('name' => 'tel', 'type' => 'xsd:int'), )); $serveur->wsdl->addComplexType( 'ContactArray', 'complexType', 'array','', 'SOAP-ENC:Array', array(), array( array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Contact[]')), 'tns:Contact' ); $serveur->register('getContacts', array(), array('Contact' => 'tns:ContactArray')); $serveur->register('addContact', array('nom' => 'xsd:string', 'prenom' => 'xsd:string', 'email' => 'xsd:string', 'tel' => 'xsd:int'), array()); //Fonction qui recupere les contacts function getContacts() { $result = array(); $req="SELECT * FROM `Contacts`"; $res=mysql_query($req); while($obj=mysql_fetch_object($res)) { $result[] = array( 'nom' => $obj->nom, 'prenom' => $obj->prenom,'email'=>$obj->email, 'tel'=>$obj->tel); } return $result; } //Fonction qui ajoute un contacte dans la base function addContact($nom,$prenom,$email,$tel) { $req="INSERT INOT `Contacts` (`id`, `nom`, `prenom`, `email`, `tel`) values ('', '$nom', '$prenom' ,'$email', '$tel')"; mysql_query($req); } $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; $serveur->service($HTTP_RAW_POST_DATA); </php> |
Catégorie(s): Développement, Iphone, Php, Tutorial | Comments (6)
Génial! Fantastique! Merveilleux!…
meeeerci ,c parfait
Merci beaucoup pour ces super tutos.
Bonne continuation !
Je craque… tout fonctionne et pourtant j’ai toujours cette erreur quand je click sur wsdl : has no namespace!
-^ ? J’ai pourtant bien défini le $namespace !
Désolé, c’est ok ça fait juste 2 jours que j’ai cette erreur dans mon code : array($title) au lieu de array(‘title’=>’xsd:string’). Difficile à voir quand on ne cherche pas au bon endroit…
Bonjour,
J’ ai essayé de parametrer le server tant bien que mal mais une erreur subsite et je ne sais comment la corriger … mes logs d’apache me renvoient :
PHP Fatal error : Class « soap_server » not found on /var/www/api/api.php on line 5 …
Comment puis je regler le probleme ? Merci.