Précédent   Forum des professionnels en informatique > PHP > Langage
Langage Forum sur le langage PHP, la POO, les conventions, la sécurité, etc. Avant de poster : FAQ Langage, toutes les FAQ PHP, cours langage et sources PHP
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 12/04/2011, 10h05   #1
Membre confirmé
 
Avatar de liquideshark
 
Homme Jamal H Tour
Chercheur en informatique
Inscription : septembre 2006
Messages : 317
Détails du profil
Informations personnelles :
Nom : Homme Jamal H Tour
Localisation : Maroc

Informations professionnelles :
Activité : Chercheur en informatique
Secteur : Service public

Informations forums :
Inscription : septembre 2006
Messages : 317
Points : 243
Points : 243
Par défaut [DEBUTANT] Client webservice en PHP

Salut,

J'ai déployé un petit webservice retournant un string helloword(). Après des tests en java ca marche super bien. En fouillant un peut sur le web pour faire un client en php j'ai écris ceci :
Code :
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
<?php
 
echo "begin";
 
// première étape : désactiver le cache lors de la phase de test
ini_set("soap.wsdl_cache_enabled", "0");
?>
<br>
<?php
echo "=========1=========== ";
// lier le client au fichier WSDL
$client = new SoapClient('http://localhost:8084/CalculatorWSApplication/helloWS?wsdl',
    array(
      "trace"      => 1,        // enable trace to view what is happening
      "exceptions" => 0,        // disable exceptions
      "cache_wsdl" => 0)         // disable any caching on the wsdl, encase you alter the wsdl server
  );
?>
<br>
<?php
 
echo "=========2========== ";
?>
<br>
<?php
 
 
// executer la methode getHello
 
 
echo $client->helloWord();
 
echo "=========3============" ;
  // display what was sent to the server (the request)
  echo "<p>Request :".htmlspecialchars($client->__getLastRequest()) ."</p>";
  // display the response from the server
  echo "<p>Response:".htmlspecialchars($client->__getLastResponse())."</p>";
 
?>
Mon serveur apache me retourne une erreur du genre
Code :
1
2
3
4
5


[Mon Apr 11 13:47:23 2011] [notice] Apache/2.2.16 (Ubuntu) PHP/5.3.3-1ubuntu9.3 with Suhosin-Patch configured -- resuming normal operations
[Mon Apr 11 13:47:30 2011] [error] [client 127.0.0.1] PHP Catchable fatal error:  Object of class stdClass could not be converted to string in /var/www/test.php on line 30, referer: http://localhost/

Je suis un bleu en php, et j'avoue ne pas comprendre ce probleme :"stdClass could not be converted to string" ma methode retourne un string c'est fou.
voici mon wsdl

Code :
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
 
<!--
 Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-740-. 
-->
&#8722;
<!--
 Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-740-. 
-->
&#8722;
<definitions targetNamespace="http://calculator.me/" name="CalculatorWSService">
&#8722;
<types>
&#8722;
<xsd:schema>
<xsd:import namespace="http://calculator.me/" schemaLocation="http://localhost:8084/CalculatorWSApplication/CalculatorWS?xsd=1"/>
</xsd:schema>
</types>
&#8722;
<message name="add">
<part name="parameters" element="tns:add"/>
</message>
&#8722;
<message name="addResponse">
<part name="parameters" element="tns:addResponse"/>
</message>
&#8722;
<message name="helloWord">
<part name="parameters" element="tns:helloWord"/>
</message>
&#8722;
<message name="helloWordResponse">
<part name="parameters" element="tns:helloWordResponse"/>
</message>
&#8722;
<message name="getarray">
<part name="parameters" element="tns:getarray"/>
</message>
&#8722;
<message name="getarrayResponse">
<part name="parameters" element="tns:getarrayResponse"/>
</message>
&#8722;
<portType name="CalculatorWS">
&#8722;
<operation name="add">
<input wsam:Action="http://calculator.me/CalculatorWS/addRequest" message="tns:add"/>
<output wsam:Action="http://calculator.me/CalculatorWS/addResponse" message="tns:addResponse"/>
</operation>
&#8722;
<operation name="helloWord">
<input wsam:Action="http://calculator.me/CalculatorWS/helloWordRequest" message="tns:helloWord"/>
<output wsam:Action="http://calculator.me/CalculatorWS/helloWordResponse" message="tns:helloWordResponse"/>
</operation>
&#8722;
<operation name="getarray">
<input wsam:Action="http://calculator.me/CalculatorWS/getarrayRequest" message="tns:getarray"/>
<output wsam:Action="http://calculator.me/CalculatorWS/getarrayResponse" message="tns:getarrayResponse"/>
</operation>
</portType>
&#8722;
<binding name="CalculatorWSPortBinding" type="tns:CalculatorWS">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
&#8722;
<operation name="add">
<soap:operation soapAction=""/>
&#8722;
<input>
<soap:body use="literal"/>
</input>
&#8722;
<output>
<soap:body use="literal"/>
</output>
</operation>
&#8722;
<operation name="helloWord">
<soap:operation soapAction=""/>
&#8722;
<input>
<soap:body use="literal"/>
</input>
&#8722;
<output>
<soap:body use="literal"/>
</output>
</operation>
&#8722;
<operation name="getarray">
<soap:operation soapAction=""/>
&#8722;
<input>
<soap:body use="literal"/>
</input>
&#8722;
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
&#8722;
<service name="CalculatorWSService">
&#8722;
<port name="CalculatorWSPort" binding="tns:CalculatorWSPortBinding">
<soap:address location="http://localhost:8084/CalculatorWSApplication/CalculatorWS"/>
</port>
</service>
</definitions>
Merci de m'éclairer
__________________
===================================
===Accroche ta charrue à l'Open source===
===================================
liquideshark est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/04/2011, 10h18   #2
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
Fais un var_dump() de tout ce que tu affiches dans un echo.
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/04/2011, 10h55   #3
Membre confirmé
 
Avatar de liquideshark
 
Homme Jamal H Tour
Chercheur en informatique
Inscription : septembre 2006
Messages : 317
Détails du profil
Informations personnelles :
Nom : Homme Jamal H Tour
Localisation : Maroc

Informations professionnelles :
Activité : Chercheur en informatique
Secteur : Service public

Informations forums :
Inscription : septembre 2006
Messages : 317
Points : 243
Points : 243
Bonjour et merci pour ton aide . j'ai pas trés bien compris "fait un var dump"

j'écris un à la fin de mon script ?

Merci
__________________
===================================
===Accroche ta charrue à l'Open source===
===================================
liquideshark est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/04/2011, 11h01   #4
Membre confirmé
 
Avatar de liquideshark
 
Homme Jamal H Tour
Chercheur en informatique
Inscription : septembre 2006
Messages : 317
Détails du profil
Informations personnelles :
Nom : Homme Jamal H Tour
Localisation : Maroc

Informations professionnelles :
Activité : Chercheur en informatique
Secteur : Service public

Informations forums :
Inscription : septembre 2006
Messages : 317
Points : 243
Points : 243
re

j'ai un peu modifié le code en ceci :
Code :
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
<?php
echo "code @ JAmal";

// première étape : désactiver le cache lors de la phase de test
ini_set("soap.wsdl_cache_enabled", "0");
?><br><?php echo "=========1=========== ";

// lier le client au fichier WSDL
$client = new SoapClient('http://localhost:8084/CalculatorWSApplication/CalculatorWS?wsdl',
    array(
      "trace"      => 1,        // enable trace to view what is happening
      "exceptions" => 0,        // disable exceptions
      "cache_wsdl" => 0)         // disable any caching on the wsdl, encase you alter the wsdl server
  );
?><br><?php echo "=========2========== ";
?><br><?php

// executer la methode getHello

$outputws = $client->helloword();

// echo $outputws;

?><br><?php

echo "==================================================================" ;
  // display what was sent to the server (the request)
  echo "<p>Request :".htmlspecialchars($client->__getLastRequest()) ."</p>";
 // display the response from the server
  echo "<p>Response:".htmlspecialchars($client->__getLastResponse())."</p>";


echo var_dump();

?>
j'ai un affichage sur ma page web :


Code :
1
2
3
4
5
6
7
8
9
10
code @ JAmal
=========1===========
=========2==========

==================================================================

Request :<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://calculator.me/"><SOAP-ENV:Body><ns1:helloWord/></SOAP-ENV:Body></SOAP-ENV:Envelope>

Response:<?xml version='1.0' encoding='UTF-8'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:helloWordResponse xmlns:ns2="http://calculator.me/"><return>HELLO JAMAL WEBSERVICE</return></ns2:helloWordResponse></S:Body></S:Envelope>

le problem viendrais de echo $outputws; je ne comprend pas. Es ce l'écriture ?

Merci
__________________
===================================
===Accroche ta charrue à l'Open source===
===================================
liquideshark est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/04/2011, 11h04   #5
Membre éprouvé
 
Avatar de radicaldreamer
 
Homme Guillaume
Développeur Web
Inscription : décembre 2007
Messages : 353
Détails du profil
Informations personnelles :
Nom : Homme Guillaume
Âge : 21
Localisation : France, Haut Rhin (Alsace)

Informations professionnelles :
Activité : Développeur Web
Secteur : High Tech - Multimédia et Internet

Informations forums :
Inscription : décembre 2007
Messages : 353
Points : 473
Points : 473
http://php.net/manual/fr/function.var-dump.php
__________________
Si ce que tu as à dire n'est pas plus beau que le silence, alors tais toi.

- Pensez à voter pour les messages qui vous ont été utiles ainsi que de mettre
radicaldreamer est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/04/2011, 11h17   #6
Membre confirmé
 
Avatar de liquideshark
 
Homme Jamal H Tour
Chercheur en informatique
Inscription : septembre 2006
Messages : 317
Détails du profil
Informations personnelles :
Nom : Homme Jamal H Tour
Localisation : Maroc

Informations professionnelles :
Activité : Chercheur en informatique
Secteur : Service public

Informations forums :
Inscription : septembre 2006
Messages : 317
Points : 243
Points : 243
Super cool ça me donne :

Code :
object(stdClass)#2 (1) { ["return"]=>  string(22) "HELLO JAMAL WEBSERVICE" }
Maintenant comment afficher juste mon string , je suis super nul en php

Merci d'avance
__________________
===================================
===Accroche ta charrue à l'Open source===
===================================
liquideshark est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/04/2011, 11h26   #7
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
$outputws est une instance de classe qui a une propriété "return" qui contient la chaine :
Code :
echo $outputws->return;
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 12/04/2011, 11h28   #8
Membre confirmé
 
Avatar de liquideshark
 
Homme Jamal H Tour
Chercheur en informatique
Inscription : septembre 2006
Messages : 317
Détails du profil
Informations personnelles :
Nom : Homme Jamal H Tour
Localisation : Maroc

Informations professionnelles :
Activité : Chercheur en informatique
Secteur : Service public

Informations forums :
Inscription : septembre 2006
Messages : 317
Points : 243
Points : 243
Citation:
Envoyé par sabotage Voir le message
$outputws est une instance de classe qui a une propriété "return" qui contient la chaine :
Code :
echo $outputws->return;
En plein dans le mille merci mille fois sabotage
__________________
===================================
===Accroche ta charrue à l'Open source===
===================================
liquideshark est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 02h45.


 
 
 
 
Partenaires

Hébergement Web