LDAP: couldn't connect to LDAP server
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
|
lpro:ws:ws_avec_wsdl [2016/01/06 12:58] jbaudry created |
lpro:ws:ws_avec_wsdl [2016/12/15 15:47] (current) jbaudry |
||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== WS avec fichier WSDL ====== | ====== WS avec fichier WSDL ====== | ||
| - | * Client php | + | * Client php client.php |
| <code php> | <code php> | ||
| <?php | <?php | ||
| Line 38: | Line 38: | ||
| ?> | ?> | ||
| + | </code> | ||
| + | |||
| + | * Serveur PHP : serveur.php | ||
| + | |||
| + | <code php> | ||
| + | <?php | ||
| + | // Pour supprimer le cache du web-service | ||
| + | ini_set('soap.wsdl_cache_enabled', 0); | ||
| + | // Pour définir le temp maximal d'éxecution de notre web-service | ||
| + | ini_set('default_socket_timeout', 180); | ||
| + | |||
| + | // Nom de notre web-service | ||
| + | class Server { | ||
| + | // Le service QuelJour que l'on a définit dans notre format wsdl | ||
| + | function Jour($parm) { | ||
| + | $aJour[1] = 'Lundi'; | ||
| + | $aJour[2] = 'Mardi'; | ||
| + | $aJour[3] = 'Mercredi'; | ||
| + | $aJour[4] = 'Jeudi'; | ||
| + | $aJour[5] = 'Vendredi'; | ||
| + | $aJour[6] = 'Samedi'; | ||
| + | $aJour[0] = 'Dimanche'; | ||
| + | return $aJour[date("w",strtotime($parm))]; | ||
| + | } | ||
| + | function hellotest($parm) { | ||
| + | return "Hello ".$parm ; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | // On tente d'instancier la classe soapServer | ||
| + | // Si cela s'avère impossible, on affiche une erreur | ||
| + | try { | ||
| + | $server = new SoapServer('Hello.wsdl', array('trace' => 1,'encoding' => 'ISO-8859-1')); | ||
| + | // On définit la classe qui va gérer les requêtes SOAP (pour nous c'est la class Server) | ||
| + | $server->setclass('Server'); | ||
| + | $server->setPersistence(SOAP_PERSISTENCE_REQUEST); | ||
| + | } catch (Exception $e) { | ||
| + | echo 'erreur'.$e; | ||
| + | } | ||
| + | |||
| + | |||
| + | /* | ||
| + | * Gestion des requêtes | ||
| + | */ | ||
| + | |||
| + | // Si l'appel provient d'un Web-Service | ||
| + | if ($_SERVER['REQUEST_METHOD'] == 'POST') { | ||
| + | try { | ||
| + | $server -> handle();} | ||
| + | catch (Exception $e) { | ||
| + | echo 'erreur'.$e; | ||
| + | } | ||
| + | } | ||
| + | // Facultatif seulement pour montrer les fonctions disponibles par le web-service | ||
| + | else { | ||
| + | echo '<strong>This SOAP server can handle following functions : </strong>'; | ||
| + | echo '<ul>'; | ||
| + | foreach($server -> getFunctions() as $func) { | ||
| + | echo '<li>' , $func , '</li>'; | ||
| + | } | ||
| + | echo '</ul>'; | ||
| + | } | ||
| + | |||
| + | |||
| + | ?> | ||
| + | </code> | ||
| + | |||
| + | * WSDL (généré avec eclipse) : Hello.wsdl | ||
| + | |||
| + | <code xml> | ||
| + | <?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
| + | <wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://www.example.org/Hello/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="Hello" targetNamespace="http://www.example.org/Hello/"> | ||
| + | <wsdl:types> | ||
| + | <xsd:schema targetNamespace="http://www.example.org/Hello/"> | ||
| + | <xsd:element name="hello"> | ||
| + | <xsd:complexType> | ||
| + | <xsd:sequence> | ||
| + | <xsd:element name="in" type="xsd:string"/> | ||
| + | </xsd:sequence> | ||
| + | </xsd:complexType> | ||
| + | </xsd:element> | ||
| + | <xsd:element name="helloResponse"> | ||
| + | <xsd:complexType> | ||
| + | <xsd:sequence> | ||
| + | <xsd:element name="out" type="xsd:string"/> | ||
| + | </xsd:sequence> | ||
| + | </xsd:complexType> | ||
| + | </xsd:element> | ||
| + | </xsd:schema> | ||
| + | </wsdl:types> | ||
| + | <wsdl:message name="hellotestRequest"> | ||
| + | <wsdl:part name="parameters" type="xsd:string"/> | ||
| + | </wsdl:message> | ||
| + | <wsdl:message name="hellotestResponse"> | ||
| + | <wsdl:part name="parameters" type="xsd:string"/> | ||
| + | </wsdl:message> | ||
| + | <wsdl:portType name="Hello"> | ||
| + | <wsdl:operation name="hellotest"> | ||
| + | <wsdl:input message="tns:hellotestRequest"/> | ||
| + | <wsdl:output message="tns:hellotestResponse"/> | ||
| + | </wsdl:operation> | ||
| + | </wsdl:portType> | ||
| + | <wsdl:binding name="HelloSOAP" type="tns:Hello"> | ||
| + | <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/> | ||
| + | <wsdl:operation name="hellotest"> | ||
| + | <soap:operation soapAction="http://www.example.org/Hello/hellotest"/> | ||
| + | <wsdl:input> | ||
| + | <soap:body use="literal"/> | ||
| + | </wsdl:input> | ||
| + | <wsdl:output> | ||
| + | <soap:body use="literal"/> | ||
| + | </wsdl:output> | ||
| + | </wsdl:operation> | ||
| + | </wsdl:binding> | ||
| + | <wsdl:service name="Hello"> | ||
| + | <wsdl:port binding="tns:HelloSOAP" name="HelloSOAP"> | ||
| + | <soap:address location="http://localhost/LPRO/2016/ex3/serveur.php"/> | ||
| + | </wsdl:port> | ||
| + | </wsdl:service> | ||
| + | </wsdl:definitions> | ||
| </code> | </code> | ||