Bonjour un tous,
J'implémente actuellement mon premier Web Service SOAP dans Symfony 2.
Et si vous prenez connaissance de cette discussion c'est que malheureusement je n'arrive pas à la faire fonctionner.
J'ai dans mon arborescence Symfony ces fichiers :
mon_appli
-----------app
-------config
----------config.yml
-----------src
-------demo
----------demoBundle
-------------Controller
---------------Resources
--------------config
------------------routing.yml
---------------ProjectsServiceController.php
-------------Services
---------------ProjectsService.php
---------------ProjectsService.wsdl
Le fichier HelloWorld.wsdl : est le fichier descriptif de mon service avec une simple méthode helloYou
Le fichier ProjectsService.php : implémente tout simplement mon service helloYou
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<?xml version="1.0" encoding="UTF-8"?> <definitions targetNamespace="urn:ProjectsServicewsdl" xmlns:tns="urn:ProjectsServicewsdl" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/"> <types> </types> <message name="helloYouRequest"> <part name="name" type="xsd:string"/> </message> <message name="helloYouResponse"> <part name="return" type="xsd:string"/> </message> <portType name="ProjectsServicewsdlPortType"> <operation name="helloYou"> <documentation></documentation> <input message="tns:helloYouRequest"/> <output message="tns:helloYouResponse"/> </operation> </portType> <binding name="ProjectsServicewsdlBinding" type="tns:ProjectsServicewsdlPortType"> <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <operation name="helloYou"> <soap:operation soapAction="urn:ProjectsServicewsdl#helloYou" style="rpc"/> <input> <soap:body use="encoded" namespace="urn:ProjectsServicewsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> <output> <soap:body use="encoded" namespace="urn:ProjectsServicewsdl" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </output> </operation> </binding> <service name="ProjectsServicewsdl"> <port name="helloYouPort" binding="tns:ProjectsServicewsdlBinding"> <soap:address location="http://127.0.0.1/xxxxx/web/soap/projects-service/sayHello" /> </port> </service> </definitions>
Dans le fichier config.yml je configure mon service :
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 namespace mon_appli\demoBundle\Services; class ProjectsService { private $message; public function __construct() { $this->message = "Hola "; } public function helloYou($name) { return $this->message+$name; } }
Le fichier ProjectsServiceController.php est le controller recevant les appels du service web par les clients
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 ... #web services services: hello_service: class: mon_appli\demoBundle\Services\ProjectsService ...
Le fichier routing.yml configure la route instanciant le controller ci-dessus
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 namespace mon_appli\demoBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Response; class ProjectsController extends Controller { private $_server; // Constructor function __construct() { ini_set('soap.wsdl_cache_enabled', '0'); ini_set('soap.wsdl_cache_ttl',0); } // Public methods public function sayHelloAction() { //$server = new \SoapServer(realpath(dirname(__DIR__)."/../Services/ProjectsService.wsdl")); $server->setObject($this->get('hello_service')); $response = new Response(); $response->headers->set('Content-Type', 'text/xml; charset=ISO-8859-1'); ob_start(); $server->handle(); $response->setContent(ob_get_clean()); return $response; }
Enfin j'ai mon client qui est un client PHP mais codé en dehors du framework Symfony
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 _ws_projects_server: pattern: /soap/projects-service/sayHello defaults: { _controller: "xxxxxdemoBundle:ProjectsService:sayHello" }
Lorsque dans le navigateur je cherche http://127.0.0.1/xxxxx/web/soap/proj.../sayHello?wsdl mon fichier wsdl est bien restitué et en mode debug je rentre bien dans la méthode sayHelloAction() de mon controlleur ProjectsController
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 try { $client = new SoapClient("http://127.0.0.1/xxxxx/web/soap/projects-service/sayHello?wsdl", array('trace'=>1, 'exceptions'=>1, 'encoding'=>'ISO-8859-1')); $result = $client->__soapCall('helloYou', array('name'=>'DUPONT')); } catch (Exception $ex) { echo $ex->message(); }
Lorsque j'execute mon client je ne rentre pas de la catch donc il ne semble pas avoir d'erreur mais mon service ne retourne pas ce dont j'attends... Quelquechose comme Hola DUPPONT
Il semble que je ne passe jamais dans ma méthode helloYou($name) de mon service ProjectsService ?.?.?...
Je ne comprends pas quel lien existe-t-il entre le controlleur recevant la demande SOAP cliente et mon service lui même ?
Je ne comprends pas non plus par ou passe mon paramètre $name envoyé à mon service ?
Quelqu'un peut-il m'éclairer ???
Par avance merci.
Partager