Bonjour,
Je voudrais pouvoir mapper un type WSDL avec un objet PHP au niveau de mon client, et cela ne fonctionne pas : j'obtiens toujours un objet de type stdclass.
Avez vous déjà rencontré ce problème ?
Voici mon code coté serveur :
- serveur de webservices : testServeur.php
- class de traitement coté serveur : class.test.php
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 <?php // on inclue la classe contenant l'objet include("class.test.php"); // On tente d'instancier la classe soapServer // Si cela s'avère impossible, on lève une exception try { //ini_set('soap.wsdl_cache_enabled', 0); $server = new SoapServer('test.wsdl', array('trace' => 1, 'encoding'=>'ISO-8859-1')); // On définit la classe qui va gérer les requètes SOAP $server -> setclass('classtest'); } catch (Exception $e) { echo $e; } // La méthode POST a été utilisée pour appeller cette page. // On suppose donc qu'une requète a été envoyée, on la gère if ($_SERVER['REQUEST_METHOD'] == 'POST' || $_SERVER['REQUEST_METHOD'] == 'GET' ) { $server -> handle(); } // sinon, on affiche une liste des méthodes que peut gérer ce serveur else { echo '<strong>This SOAP server can handle following functions : </strong>'; echo '<ul>'; foreach($server -> getFunctions() as $func) { echo '<li>' , $func , '</li>'; } echo '</ul>'; } ?>
- le wsdl : test.wsdl
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 <? class person { public $name; function getName() { return $name; } } class classtest { function getPerson($nom) { $personne = & new person(); $personne->name = $nom; return $personne; } } ?>
Et voici mon client : testClient.php
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<?xml version="1.0" encoding="ISO-8859-1"?> <definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://localhost/myns/" xmlns:soap-env="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="http://localhost/myns/"> <types> <xsd:schema> <complexType name="person"> <all> <element name="name" type="xsd:string"/> </all> </complexType> </xsd:schema> </types> <message name="getPersonInput"> <part name="chaine" type="xsd:string"/> </message> <message name="getPersonOutput"> <part name="retour" type="tns:person"/> </message> <portType name="TestPortType"> <operation name="getPerson"> <input message="tns:getPersonInput"/> <output message="tns:getPersonOutput"/> </operation> </portType> <binding name="TestBinding" type="tns:TestPortType"> <soap-env:binding xmlns="http://schemas.xmlsoap.org/wsdl/soap/" style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/> <operation xmlns:default="http://schemas.xmlsoap.org/wsdl/soap/" name="getPerson"> <input xmlns:default="http://schemas.xmlsoap.org/wsdl/soap/"> <soap-env:body xmlns="http://schemas.xmlsoap.org/wsdl/soap/" use="encoded" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> </input> </operation> </binding> <service name="TestService"> <port xmlns:default="http://schemas.xmlsoap.org/wsdl/soap/" name="TestPort" binding="tns:TestBinding"> <soap-env:address xmlns="http://schemas.xmlsoap.org/wsdl/soap/" location="http://localhost/ws/test/testServeur.php"/> </port> </service> </definitions>
Et voici le resultat sous IE :
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 <? class person { public $name; function getName() { return $name; } } $_adr_portail = "http://localhost"; $_chemin_ws = "/ws/test/"; $classmap = array("person" => "person"); ini_set('soap.wsdl_cache_enabled', 0); $_options = array( "classmap" => $classmap, "trace" => 1, "namespace" => $_adr_portail."/myns/" ); $ficWSDL = $_adr_portail.$_chemin_ws."testServeur.php?WSDL"; $_clientSOAP = new SoapClient($ficWSDL, $_options); $retour = $_clientSOAP->getPerson("toto"); print "<pre>"; print_r($retour); print "</pre>"; echo $retour->getName(); ?>
stdClass Object
(
[name] => toto
)
Fatal error: Call to undefined method stdClass::getName() in D:\wamp\www\ws\test\testClient.php on line 33
Merci d'avance pour l'aide que vous pouvez m'apporter !
Partager