IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

[DEBUTANT] Client webservice en PHP


Sujet :

Langage PHP

  1. #1
    Membre averti Avatar de liquideshark
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Septembre 2006
    Messages
    347
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

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

    Informations forums :
    Inscription : Septembre 2006
    Messages : 347
    Points : 325
    Points
    325
    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 : 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
    <?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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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 : 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
    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-. 
    -->
    −
    <!--
     Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.2-hudson-740-. 
    -->
    −
    <definitions targetNamespace="http://calculator.me/" name="CalculatorWSService">
    −
    <types>
    −
    <xsd:schema>
    <xsd:import namespace="http://calculator.me/" schemaLocation="http://localhost:8084/CalculatorWSApplication/CalculatorWS?xsd=1"/>
    </xsd:schema>
    </types>
    −
    <message name="add">
    <part name="parameters" element="tns:add"/>
    </message>
    −
    <message name="addResponse">
    <part name="parameters" element="tns:addResponse"/>
    </message>
    −
    <message name="helloWord">
    <part name="parameters" element="tns:helloWord"/>
    </message>
    −
    <message name="helloWordResponse">
    <part name="parameters" element="tns:helloWordResponse"/>
    </message>
    −
    <message name="getarray">
    <part name="parameters" element="tns:getarray"/>
    </message>
    −
    <message name="getarrayResponse">
    <part name="parameters" element="tns:getarrayResponse"/>
    </message>
    −
    <portType name="CalculatorWS">
    −
    <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>
    −
    <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>
    −
    <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>
    −
    <binding name="CalculatorWSPortBinding" type="tns:CalculatorWS">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
    −
    <operation name="add">
    <soap:operation soapAction=""/>
    −
    <input>
    <soap:body use="literal"/>
    </input>
    −
    <output>
    <soap:body use="literal"/>
    </output>
    </operation>
    −
    <operation name="helloWord">
    <soap:operation soapAction=""/>
    −
    <input>
    <soap:body use="literal"/>
    </input>
    −
    <output>
    <soap:body use="literal"/>
    </output>
    </operation>
    −
    <operation name="getarray">
    <soap:operation soapAction=""/>
    −
    <input>
    <soap:body use="literal"/>
    </input>
    −
    <output>
    <soap:body use="literal"/>
    </output>
    </operation>
    </binding>
    −
    <service name="CalculatorWSService">
    −
    <port name="CalculatorWSPort" binding="tns:CalculatorWSPortBinding">
    <soap:address location="http://localhost:8084/CalculatorWSApplication/CalculatorWS"/>
    </port>
    </service>
    </definitions>
    Merci de m'éclairer

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Fais un var_dump() de tout ce que tu affiches dans un echo.

  3. #3
    Membre averti Avatar de liquideshark
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Septembre 2006
    Messages
    347
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

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

    Informations forums :
    Inscription : Septembre 2006
    Messages : 347
    Points : 325
    Points
    325
    Par défaut
    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

  4. #4
    Membre averti Avatar de liquideshark
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Septembre 2006
    Messages
    347
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

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

    Informations forums :
    Inscription : Septembre 2006
    Messages : 347
    Points : 325
    Points
    325
    Par défaut
    re

    j'ai un peu modifié le code en ceci :
    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
    <?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 : Sélectionner tout - Visualiser dans une fenêtre à part
    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

  5. #5
    Membre confirmé Avatar de rikemSen
    Homme Profil pro
    Analyste Développeur Web - Fizzup.com
    Inscrit en
    Décembre 2007
    Messages
    387
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : France, Bas Rhin (Alsace)

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

    Informations forums :
    Inscription : Décembre 2007
    Messages : 387
    Points : 540
    Points
    540

  6. #6
    Membre averti Avatar de liquideshark
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Septembre 2006
    Messages
    347
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

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

    Informations forums :
    Inscription : Septembre 2006
    Messages : 347
    Points : 325
    Points
    325
    Par défaut
    Super cool ça me donne :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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

  7. #7
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    $outputws est une instance de classe qui a une propriété "return" qui contient la chaine :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    echo $outputws->return;

  8. #8
    Membre averti Avatar de liquideshark
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Septembre 2006
    Messages
    347
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Maroc

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

    Informations forums :
    Inscription : Septembre 2006
    Messages : 347
    Points : 325
    Points
    325
    Par défaut
    Citation Envoyé par sabotage Voir le message
    $outputws est une instance de classe qui a une propriété "return" qui contient la chaine :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    echo $outputws->return;
    En plein dans le mille merci mille fois sabotage

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Passage d'un client SOAP de PHP à C
    Par olivier857 dans le forum C
    Réponses: 10
    Dernier message: 24/04/2006, 16h05
  2. relation client- serveur js php
    Par sylvain1981 dans le forum Général Conception Web
    Réponses: 2
    Dernier message: 14/03/2006, 09h58
  3. [debutant][client distant] droit d'accès
    Par Invité dans le forum MS SQL Server
    Réponses: 4
    Dernier message: 23/02/2006, 11h51
  4. XML et PHP - Debutant - Generation XML en php
    Par FiSh MoOn dans le forum XML/XSL et SOAP
    Réponses: 1
    Dernier message: 04/11/2005, 00h39
  5. Créer un Webservice en PHP
    Par Amnesiak dans le forum Langage
    Réponses: 3
    Dernier message: 07/10/2005, 15h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo