[PHP] Webservice SOAP - Requête XML et type complexe ?

WRInaute passionné
Bonjour,

Dans une requête SOAP, je cherche comment envoyer un type complexe en paramètre.

Voici mon fichier WSDL avec mon type complexe "information".
Code:
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="test" targetNamespace="urn:WS/wsdl"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="urn:WS/wsdl" xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/">
    <types>
        <xsd:schema targetNamespace="urn:WS/wsdl" xmlns:tns="urn:WS/wsdl">
            <xsd:complexType name="information">
                <xsd:sequence>
                    <xsd:element name="version" type="xsd:string"></xsd:element>
                    <xsd:element name="id" type="xsd:int"></xsd:element>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:schema>
    </types>
    <message name="getDateRequest"/>
    <message name="getDateResponse">
        <part name="date" type="xsd:date"/>
    </message>
    <message name="getXmlRequest">
        <part name="information" type="tns:information"/>
    </message>
    <message name="getXmlResponse">
        <part name="version" type="xsd:string"/>
    </message>
    <portType name="Date">
        <operation name="getDate">
            <input name="input1" message="tns:getDateRequest"/>
            <output name="output1" message="tns:getDateResponse"/>
        </operation>
        <operation name="getXml">
            <input name="input2" message="tns:getXmlRequest"/>
            <output name="output2" message="tns:getXmlResponse"/>
        </operation>
    </portType>
    <binding name="testBinding" type="tns:Date">
        <soap12:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="getDate">
            <soap12:operation/>
            <input name="input1">
                <soap12:body use="literal" namespace="urn:WS/wsdl"/>
            </input>
            <output name="output1">
                <soap12:body use="literal" namespace="urn:WS/wsdl"/>
            </output>
        </operation>
        <operation name="getXml">
            <input name="input2"/>
            <output name="output2"/>
        </operation>
    </binding>
    <service name="testService">
        <port name="testPort" binding="tns:testBinding">
            <soap12:address location="http://127.0.0.1:1004/webservice/server.php"/>
        </port>
    </service>
    <plnk:partnerLinkType name="test">
        <!-- A partner link type is automatically generated when a new port type is added. Partner link types are used by BPEL processes.
In a BPEL process, a partner link represents the interaction between the BPEL process and a partner service. Each partner link is associated with a partner link type.
A partner link type characterizes the conversational relationship between two services. The partner link type can have one or two roles.-->
        <plnk:role name="DateRole" portType="tns:Date"/>
    </plnk:partnerLinkType>
</definitions>
Mon type complexe "information " est constitué d'un élément "version" et "id".

Après quelques essaies, je ne parviens pas du côté client à envoyer ces paramètres dans un appel de méthode "getXml".
Voici ce que j'ai essayé de faire.

Code:
$client = new SoapClient('http://127.0.0.1:1004/webservice/test.wsdl', array('trace' => 1, 'soap_version'  => SOAP_1_2));
$xml = '<?xml version="1.0" encoding="UTF-8"?>';
    $xml .= '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">';
    $xml .= '<SOAP-ENV:Body>';
    $xml .= '<SOAP-ENV:getXml>';
        $xml .= '<information>';
            $xml .= '<version>test version</version>';
            $xml .= '<id>55555</id>';
        $xml .= '</information>';
    $xml .= '</SOAP-ENV:getXml>';
    $xml .= '</SOAP-ENV:Body>';
    $xml .= '</SOAP-ENV:Envelope>';
echo $client->getXml($xml);

Comment travailler avec un type complexe ?
Comment le fournir en paramètre côté client et comment le récupérer côté serveur ?

Je suis preneur de tous conseils.

Merci.
 
WRInaute accro
Euh... Je n'utilise pas php donc encore moins SoapClient, mais le but de la classe n'est-il pas justement de ne pas avoir à formater le xml soi-même? Tu ne devrais pas juste faire un $client->getXML($version,$id)? Ou peut-être $client->getXML(array($version,$id)); Ou encore $client->getXML(array(version=>$version,id=>$id));

Jacques.
 
WRInaute passionné
jcaron a dit:
mais le but de la classe n'est-il pas justement de ne pas avoir à formater le xml soi-même?
Oui, certainement et cela fonctionne sans problème.

Mon problème est fait de savoir comment exécuter directement la requête par flux XML.

Déjà je viens de m'apercevoir qu'il faut absolument passer par SoapClient::__doRequest qui exécute une requête SOAP.

http://fr.php.net/manual/fr/soapclient.dorequest.php

Voici ce que j'ai essayé de faire (je suis sûr de la requête qui a été auto-générée par un passage de paramètre avec un tableau).

Code:
    $req = '<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="urn:WS/wsdl" xmlns:ns2="http://127.0.0.1:1004/webservice/newXmlSchema"><env:Body><ns1:testXml><flux><ns2:id ref="reférence n°2" key="key n°2">2222</ns2:id><ns2:version>v 2.0</ns2:version></flux></ns1:testXml></env:Body></env:Envelope>';

    echo $client->__doRequest($req,
                                'http://127.0.0.1:1004/webservice/server.php',
                                'soapXml',
                                SOAP_1_2);

Je n'obtiens toujours pas plus de succès et je n'arrive pas trop à cerner à quoi correspondent les paramètres :
- string $location,
- string $action.

Qui a une idée ?

Merci

Fichier WSDL
Code:
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="test" targetNamespace="urn:WS/wsdl"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns="http://127.0.0.1:1004/webservice/newXmlSchema" xmlns:plnk="http://docs.oasis-open.org/wsbpel/2.0/plnktype" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:tns="urn:WS/wsdl">
    <types>
        <xsd:schema targetNamespace="urn:WS/wsdl">
            <xsd:import namespace="http://127.0.0.1:1004/webservice/newXmlSchema" schemaLocation="newXmlSchema.xsd"/>
        </xsd:schema>
    </types>
    <message name="testXmlRequest">
        <part name="flux" type="ns:produit"/>
    </message>
    <message name="testXmlResponse">
        <part name="reponse" type="xsd:string"/>
    </message>
    <portType name="testPortType">
        <operation name="testXml">
            <input name="input1" message="tns:testXmlRequest"/>
            <output name="output1" message="tns:testXmlResponse"/>
        </operation>
    </portType>
    <binding name="testBinding" type="tns:testPortType">
        <soap12:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
        <operation name="testXml">
            <soap12:operation soapAction="soapXml"/>
            <input name="input1">
                <soap12:body use="literal" namespace="urn:WS/wsdl"/>
            </input>
            <output name="output1">
                <soap12:body use="literal" namespace="urn:WS/wsdl"/>
            </output>
        </operation>
    </binding>
    <service name="testService">
        <port name="testPort" binding="tns:testBinding">
            <soap12:address location="http://127.0.0.1:1004/webservice/server.php"/>
        </port>
    </service>
    <plnk:partnerLinkType name="test">
        <!-- A partner link type is automatically generated when a new port type is added. Partner link types are used by BPEL processes.
In a BPEL process, a partner link represents the interaction between the BPEL process and a partner service. Each partner link is associated with a partner link type.
A partner link type characterizes the conversational relationship between two services. The partner link type can have one or two roles.-->
        <plnk:role name="testPortTypeRole" portType="tns:testPortType"/>
    </plnk:partnerLinkType>
</definitions>
 
WRInaute impliqué
Quel est l'interet de la classe SoapClient si tu dois mettre ton XML à la main ? Lis bien la documentation, elle ne doit pas s'utiliser comme ça, c'est sûr.
 
WRInaute passionné
La n'est pas la question. Pour diverses raisons, j'ai besoin de tester le flux XML brut.
De plus il existe une méthode qui permet de la faire. J'aimerais juste y arriver.
Merci.
 
WRInaute accro
Si tu veux vraiment balancer du XML brut, un bon coup de fsockopen ou autre chose de ce genre devrait suffire, non? Dans ce cas-là tu te prends la réponse en XML brut aussi évidemment...

Jacques.
 
Discussions similaires
Haut