[RESOLU] Soap Web Service Request Response

Répondre


Cette question est un moyen d’empêcher des soumissions automatisées de formulaires par des robots.
Smileys
:D :) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: =D> #-o =P~ :^o :non: :priere: 8-|
Voir plus de smileys
  Revue du sujet
 

  Étendre la vue Revue du sujet : [RESOLU] Soap Web Service Request Response

Re: Soap Web Service Request Response

par Henrigo » 15 févr. 2021, 14:05

Merci infiniment, ca ete tres gentil avec cet explication final

Re: Soap Web Service Request Response

par Ryle » 15 févr. 2021, 13:15

En fait, l'appel soap te retourne une grosse chaine de caractère contenant les balises et leur contenu. C'est celui-ci que tu vas ensuite analyser pour récupérer la où les informations dont tu as besoin pour les afficher ou les utiliser dans d'autres traitements.

Si tu affiches la chaine juste avec un echo, le navigateur va essayer d'interpréter les balises comme s'il s'agissait de html (elles n'apparaitront pas à l'écran, mais seront bien présentes dans le code source de la page) et afficher le texte sans aucune mise en forme (retour à la ligne, tabulation, etc.).

Si tu utilises en plus la fonction htmlentities(), les balises < et > seront transformées en entités html, ce qui évite que le navigateur ne les considère comme des balises html et l'intégralité de la chaine est alors affichée, mais toujours sans mise en forme. (c'est le résultat que tu semble obtenir)

Enfin, le fait d'afficher cette chaine entre les balises <pre> et </pre> doit te permettre de conserver les retours à la ligne et les tabulations à l'affichage dans le navigateur pour que le flux reçu ou envoyé soit plus facile à lire.

Mais il faut pour cela que ces retours à la ligne et les tabulations soient bien présentes dans le flux envoyé par le serveur. Si le serveur se contente de retourner tous les éléments sans mise en forme (et il me semble que c'est le cas ici), tu ne pourras pas obtenir mieux. Mais une fois encore, ce qui compte c'est que l'information dont tu as besoin soit présente, pas la façon dont elle est affichée. L'idée étant de récupérer les informations dont tu as besoin (l'id du produit, son titre, sa description...) et ensuite de les mettre en forme comme bon te semble. Et là tu pourras utiliser du html pour format des titres ou du php (avec nl2br() par exemple) pour mettre en forme la description en ajoutant automatiquement des <br> lorsqu'il y a un retour à la ligne :)

Re: Soap Web Service Request Response

par Henrigo » 15 févr. 2021, 12:40

Salut Ryle,
merci bien de ta proposition, effectivement je recois deja le resultat mais le formatage n'y est pas ou alors le redacteur a eu un faire un formatage manuel car voici a quoi ressemble le resultat Request et response

Request
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn://localhost/soap/server.php" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:getAllProducts/></SOAP-ENV:Body></SOAP-ENV:Envelope>
Response
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/soap/server.php" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:getAllProductsResponse><return SOAP-ENC:arrayType="SOAP-ENC:Struct[4]" xsi:type="SOAP-ENC:Array"><item xsi:type="SOAP-ENC:Struct"><id xsi:type="xsd:string">1</id><title xsi:type="xsd:string">Details about  Canon EF 50mm f/1.8 STM Lens</title><description xsi:type="xsd:string">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</description><price xsi:type="xsd:string">$89.99</price></item><item xsi:type="SOAP-ENC:Struct"><id xsi:type="xsd:string">2</id><title xsi:type="xsd:string">Refurbished Dell Latitude E5420 Laptop - i3 - 4GB RAM - 250GB HDD - Win 10 Pro</title><description xsi:type="xsd:string">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting.</description><price xsi:type="xsd:string">US $4.08</price></item><item xsi:type="SOAP-ENC:Struct"><id xsi:type="xsd:string">3</id><title xsi:type="xsd:string"> Details about  M3 Sport Fitness Smart Wrist Band Pedometer Activity Tracker Bracelet Watch New </title><description xsi:type="xsd:string">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</description><price xsi:type="xsd:string">$5.50</price></item><item xsi:type="SOAP-ENC:Struct"><id xsi:type="xsd:string">4</id><title xsi:type="xsd:string"> Details about  Samsung Galaxy S9+ Plus(LATEST) SM-G965U 64GB T-Mobile AT&amp;T Verizon GSM Unlocked</title><description xsi:type="xsd:string">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries</description><price xsi:type="xsd:string">$399.88</price></item></return></ns1:getAllProductsResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
Request
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn://localhost/soap/server.php" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:getAllProducts/></SOAP-ENV:Body></SOAP-ENV:Envelope>
Response
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/soap/server.php" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:getAllProductsResponse><return SOAP-ENC:arrayType="SOAP-ENC:Struct[4]" xsi:type="SOAP-ENC:Array"><item xsi:type="SOAP-ENC:Struct"><id xsi:type="xsd:string">1</id><title xsi:type="xsd:string">Details about  Canon EF 50mm f/1.8 STM Lens</title><description xsi:type="xsd:string">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</description><price xsi:type="xsd:string">$89.99</price></item><item xsi:type="SOAP-ENC:Struct"><id xsi:type="xsd:string">2</id><title xsi:type="xsd:string">Refurbished Dell Latitude E5420 Laptop - i3 - 4GB RAM - 250GB HDD - Win 10 Pro</title><description xsi:type="xsd:string">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting.</description><price xsi:type="xsd:string">US $4.08</price></item><item xsi:type="SOAP-ENC:Struct"><id xsi:type="xsd:string">3</id><title xsi:type="xsd:string"> Details about  M3 Sport Fitness Smart Wrist Band Pedometer Activity Tracker Bracelet Watch New </title><description xsi:type="xsd:string">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</description><price xsi:type="xsd:string">$5.50</price></item><item xsi:type="SOAP-ENC:Struct"><id xsi:type="xsd:string">4</id><title xsi:type="xsd:string"> Details about  Samsung Galaxy S9+ Plus(LATEST) SM-G965U 64GB T-Mobile AT&amp;T Verizon GSM Unlocked</title><description xsi:type="xsd:string">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries</description><price xsi:type="xsd:string">$399.88</price></item></return></ns1:getAllProductsResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>

Re: Soap Web Service Request Response

par Ryle » 15 févr. 2021, 10:55

Salutations !

En fait la dernière portion de code que tu nous présentes n'a que peu d'intérêt d'un point de vue métier et a surtout pour objectif de te permettre de consulter le détail du flux que tu as envoyé au serveur et sa réponse.

Il serait donc à placer dans ta classe "client" (puisqu'il fait référence à $this->soap_instance), et plus précisément dans la méthode getAll() ou getById() selon celle dont tu souhaites contrôler le fonctionnement. Il faut cependant modifier quelque peu celles-ci pour pouvoir insérer ce code entre l'appel au serveur et le retour de la méthode.
Par exemple avec getAll :
public function getAll() {
    try {       
//        return $this->soap_instance->getAllProducts(); // au lieu de faire un return du résultat de l'appel
        $res = $this->soap_instance->getAllProducts(); // on fait d'abord l'appel (on garde le résultat dans $res)

        // tu peux alors insérer le code ici pour voir les flux qui ont été envoyés et retournés

        return $res; // et enfin on retourne le résultat pour affichage ou autre...
    } catch (Exception $ex) {
        exit("soap error: " . $ex->getMessage());
    }
}

Soap Web Service Request Response

par Henrigo » 14 févr. 2021, 22:56

j'ai un probleme sur un tutoriel que j'ai trouvé en ligne, malheureusement il ya quelque chose que je ne sais pas exactement ou je devrais changer mon code pour arriver au resultat souhaité.
j'aimerai attendre un resultat comme au debut du tutoriel a savoir un

Soap-Request
<?xml version="1.0" ?>
<SOAP-ENV:Envelope
    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    >
        <!-- Optional Soap Header -->
    <SOAP-ENV:Header>
        
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
               
                <!-- Function names and attributes -->
                <getProduct>
                          <id>1</id>
                </getProduct>

                <!-- Optional Soap Fault -->
        <SOAP-ENV:Fault>
        
        </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

et Soap-Response.
<?xml version="1.0" ?>
<SOAP-ENV:Envelope
    SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
        xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    >
        <!-- Optional Soap Header -->
    <SOAP-ENV:Header>
        
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
               
                <!-- Function names and attributes -->
                <getProductResponse>
                          <return>
                                 <id>1</i>
                                 <title>Apple PC</title>
                                 <price>1000</price>
                          </return>
                </getProductResponse>

                <!-- Optional Soap Fault -->
        <SOAP-ENV:Fault>
        
        </SOAP-ENV:Fault>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
le tutoriel n'est pas long il est en anglais. le lien est le suivant
https://webmobtuts.com/backend-develop ... _vignette
je voudrais savoir a quel niveau je devrais inserer ce morceau de code suivant pour atteindre le resultat souhaité comme le dit le redacteur
echo "<pre>";

echo htmlentities($this->soap_instance->__getLastRequest());

echo "</pre>";

echo "<pre>";

echo htmlentities($this->soap_instance->__getLastResponse());

echo "</pre>";
Ca serait vraiment gentil si vraiment quelqu'un ici me onnait un coup de mains.
S'il ya d'autres questions n'hesitez pas.

Merci d'avance.