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 :

[SOAP] soapClient : requete complexe


Sujet :

Langage PHP

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2012
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Août 2012
    Messages : 2
    Points : 1
    Points
    1
    Par défaut [SOAP] soapClient : requete complexe
    J'ai un problème pour les requêtes complexes SOAP avec l'objet soapClient de php5

    PHP Version 5.3.3-1 sous ubuntu9.10

    Voici la requête SOAP que je voudrais envoyé (ici le code est en xml pour mieux le visualiser)

    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
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:epcglobal:epcis-query:xsd:1">
       <soapenv:Header/>
       <soapenv:Body>
           <urn:Poll>
             <queryName>SimpleEventQuery</queryName>
             <params>            
                <param>
                   <name>EQ_action</name>
                   <value>
    		   <string>ADD</string>
                       <string>OBSERVE</string>
    		   <string>DELETE</string>
                   </value>
                </param>
             </params>
          </urn:Poll>
       </soapenv:Body>
    </soapenv:Envelope>
    Et voici le code PHP que j'utilise pour effectuer l'appel SOAP (donc l utilisation de SoapClient pour consumer un webservice distant via un 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
     
    <?php
    /**
    * Cree un client soap pour consommer un webService 
    * On utilise l objet SoapClient de PHP http://www.php.net/manual/fr/soapclient.soapclient.php
    * RMQ : la config du proxy est dans le fichier de configuration "conf/conf/network.cfg.php"
    * 
    * @param boolean $proxy
    * @return \SoapClient 
    */
    private function getSoapclient($proxy = false)
    {				
    	$options = array("soap_version" => SOAP_1_1,
    			 "encoding"     => "UTF-8",
    			 "trace"        => true,
    			 "exceptions"   => true);
     
    	//creation d'un objet soapClient par connexion proxy
    	$soapClient = new SoapClient($this->urlWSDL, $options);
     
    	return $soapClient;
    }
     
    public function testSoap()
    {		
    	$soapClient = $this->getSoapclient();
     
    	$functionArguments = new stdClass();
    	$functionArguments->queryName = "SimpleEventQuery";
     
    	$paramMatchEpc = new stdClass();
    	$paramMatchEpc->name = "EQ_action";
    	$paramMatchEpc->value = new stdClass();
    	$paramMatchEpc->value->string = array("ADD", "OBSERVE", "DELETE");
     
    	$arrayArguments =  array($paramMatchEpc);
     
    	$functionArguments->params = new stdClass();
    	$functionArguments->params->param = $arrayArguments;
     
    	try
    	{
    		$results = $soapClient->poll($functionArguments);
    		/**/error_log(print_r($results, true));
    	} 
    	catch (Exception $exc)
    	{
    		/**/error_log("ERREUR !");
    		/**/error_log(print_r($exc, true));
    		$results = null;
    	}
     
    	return $results;
    }
    ?>

    Le code produit pour l'appel Soap n'est pas correct et provoque une horreur une erreur :p
    (le code devrait être identique à la première section de code que j'ai posté plus haut)
    Voici le code que j'obtiens (code qui n'est pas correct)


    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
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns1="urn:epcglobal:epcis-query:xsd:1">
    <SOAP-ENV:Body>
       <ns1:Poll>
          <queryName>SimpleEventQuery</queryName>
          <params>
             <param>
                <name>EQ_action</name>
                <value>
                   <string>
                      <xsd:string>ADD</xsd:string>
                      <xsd:string>OBSERVE</xsd:string>
                      <xsd:string>DELETE</xsd:string>
                   </string>
                </value>
              </param>
           </params>
       </ns1:Poll>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    Le problème provient du array de value dans le passage de paramètres car le serveurSoap ou php convertit implicitement mes strings comme des noeuds <xsd:string>MonString</xsd:string>

    Cela fait plusieurs jours que je suis dessus et je ne trouve pas de solution...
    Si une personne à une idée je suis preneur ^^

    voici le WSDL à disposition (c'est un WSDL faisait partie d un projet open source nommé fosstrak)

    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
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    <?xml version='1.0' encoding='UTF-8'?><wsdl:definitions name="QueryOperationsWebServiceService" targetNamespace="http://query.repository.epcis.fosstrak.org/" xmlns:ns1="urn:epcglobal:epcis:wsdl:1" xmlns:ns3="http://cxf.apache.org/bindings/xformat" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://query.repository.epcis.fosstrak.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <wsdl:import location="http://localhost:8080/epcis-repository-0.5.0/query/?wsdl=EPCISServicePortType.wsdl" namespace="urn:epcglobal:epcis:wsdl:1">
        </wsdl:import>
      <wsdl:binding name="QueryOperationsWebServiceServiceSoapBinding" type="ns1:EPCISServicePortType">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
        <wsdl:operation name="getQueryNames">
          <soap:operation soapAction="" style="document" />
          <wsdl:input name="getQueryNames">
            <soap:body use="literal" />
          </wsdl:input>
          <wsdl:output name="getQueryNamesResponse">
            <soap:body use="literal" />
          </wsdl:output>
          <wsdl:fault name="ImplementationExceptionResponse">
            <soap:fault name="ImplementationExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="ValidationExceptionResponse">
            <soap:fault name="ValidationExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="SecurityExceptionResponse">
            <soap:fault name="SecurityExceptionResponse" use="literal" />
          </wsdl:fault>
        </wsdl:operation>
        <wsdl:operation name="unsubscribe">
          <soap:operation soapAction="" style="document" />
          <wsdl:input name="unsubscribe">
            <soap:body use="literal" />
          </wsdl:input>
          <wsdl:output name="unsubscribeResponse">
            <soap:body use="literal" />
          </wsdl:output>
          <wsdl:fault name="ImplementationExceptionResponse">
            <soap:fault name="ImplementationExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="ValidationExceptionResponse">
            <soap:fault name="ValidationExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="NoSuchSubscriptionExceptionResponse">
            <soap:fault name="NoSuchSubscriptionExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="SecurityExceptionResponse">
            <soap:fault name="SecurityExceptionResponse" use="literal" />
          </wsdl:fault>
        </wsdl:operation>
        <wsdl:operation name="poll">
          <soap:operation soapAction="" style="document" />
          <wsdl:input name="poll">
            <soap:body use="literal" />
          </wsdl:input>
          <wsdl:output name="pollResponse">
            <soap:body use="literal" />
          </wsdl:output>
          <wsdl:fault name="QueryTooComplexExceptionResponse">
            <soap:fault name="QueryTooComplexExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="ImplementationExceptionResponse">
            <soap:fault name="ImplementationExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="QueryParameterExceptionResponse">
            <soap:fault name="QueryParameterExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="ValidationExceptionResponse">
            <soap:fault name="ValidationExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="QueryTooLargeExceptionResponse">
            <soap:fault name="QueryTooLargeExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="SecurityExceptionResponse">
            <soap:fault name="SecurityExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="NoSuchNameExceptionResponse">
            <soap:fault name="NoSuchNameExceptionResponse" use="literal" />
          </wsdl:fault>
        </wsdl:operation>
        <wsdl:operation name="subscribe">
          <soap:operation soapAction="" style="document" />
          <wsdl:input name="subscribe">
            <soap:body use="literal" />
          </wsdl:input>
          <wsdl:output name="subscribeResponse">
            <soap:body use="literal" />
          </wsdl:output>
          <wsdl:fault name="QueryTooComplexExceptionResponse">
            <soap:fault name="QueryTooComplexExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="ImplementationExceptionResponse">
            <soap:fault name="ImplementationExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="SubscriptionControlsExceptionResponse">
            <soap:fault name="SubscriptionControlsExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="QueryParameterExceptionResponse">
            <soap:fault name="QueryParameterExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="ValidationExceptionResponse">
            <soap:fault name="ValidationExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="DuplicateSubscriptionExceptionResponse">
            <soap:fault name="DuplicateSubscriptionExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="SecurityExceptionResponse">
            <soap:fault name="SecurityExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="NoSuchNameExceptionResponse">
            <soap:fault name="NoSuchNameExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="SubscribeNotPermittedExceptionResponse">
            <soap:fault name="SubscribeNotPermittedExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="InvalidURIExceptionResponse">
            <soap:fault name="InvalidURIExceptionResponse" use="literal" />
          </wsdl:fault>
        </wsdl:operation>
        <wsdl:operation name="getVendorVersion">
          <soap:operation soapAction="" style="document" />
          <wsdl:input name="getVendorVersion">
            <soap:body use="literal" />
          </wsdl:input>
          <wsdl:output name="getVendorVersionResponse">
            <soap:body use="literal" />
          </wsdl:output>
          <wsdl:fault name="ImplementationExceptionResponse">
            <soap:fault name="ImplementationExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="ValidationExceptionResponse">
            <soap:fault name="ValidationExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="SecurityExceptionResponse">
            <soap:fault name="SecurityExceptionResponse" use="literal" />
          </wsdl:fault>
        </wsdl:operation>
        <wsdl:operation name="getStandardVersion">
          <soap:operation soapAction="" style="document" />
          <wsdl:input name="getStandardVersion">
            <soap:body use="literal" />
          </wsdl:input>
          <wsdl:output name="getStandardVersionResponse">
            <soap:body use="literal" />
          </wsdl:output>
          <wsdl:fault name="ImplementationExceptionResponse">
            <soap:fault name="ImplementationExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="ValidationExceptionResponse">
            <soap:fault name="ValidationExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="SecurityExceptionResponse">
            <soap:fault name="SecurityExceptionResponse" use="literal" />
          </wsdl:fault>
        </wsdl:operation>
        <wsdl:operation name="getSubscriptionIDs">
          <soap:operation soapAction="" style="document" />
          <wsdl:input name="getSubscriptionIDs">
            <soap:body use="literal" />
          </wsdl:input>
          <wsdl:output name="getSubscriptionIDsResponse">
            <soap:body use="literal" />
          </wsdl:output>
          <wsdl:fault name="ImplementationExceptionResponse">
            <soap:fault name="ImplementationExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="ValidationExceptionResponse">
            <soap:fault name="ValidationExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="SecurityExceptionResponse">
            <soap:fault name="SecurityExceptionResponse" use="literal" />
          </wsdl:fault>
          <wsdl:fault name="NoSuchNameExceptionResponse">
            <soap:fault name="NoSuchNameExceptionResponse" use="literal" />
          </wsdl:fault>
        </wsdl:operation>
      </wsdl:binding>
      <wsdl:service name="QueryOperationsWebServiceService">
        <wsdl:port binding="tns:QueryOperationsWebServiceServiceSoapBinding" name="QueryOperationsWebServicePort">
          <soap:address location="http://localhost:8080/epcis-repository-0.5.0/query/" />
        </wsdl:port>
      </wsdl:service>
    </wsdl:definitions>

  2. #2
    Nouveau Candidat au Club
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Août 2012
    Messages
    2
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Août 2012
    Messages : 2
    Points : 1
    Points
    1
    Par défaut
    J'ai trouvé une réponse à mon problème grace à un commentaire (http://www.php.net/manual/en/soapvar.soapvar.php) trouvé dans la doc de PHP qui explique très bien l'utilisation de paramètres complexe dans les appel au web service en PHP via SOAP.

    LA SOLUTION est d'utiliser new SoapVar("<maBalise>valeur</maBalise>", XSD_ANYXML);

    Je poste le commentaire (on sait jms ça peut tjs aider quelqu'un ^^ )

    It took me more than one day to figure out how to use the SoapVar object in a multilevel/complex SOAP request.
    If you want to set-up a multilevel/complex SOAP call with parameters in subnodes, you can use the following methods:

    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
    <?php
    /* Simple example with array as parameter */
    $wsdl_url = '';
    $client     = new SoapClient($wsdl_url, array('trace' => true));       
    $parameters = array(
        'FromCurrency' => 'EUR',
        'ToCurrency' => 'AUD',
    );
     
    $client->ConversionRate($parameters);     
    echo htmlentities($client->__getLastRequest());
     
    /* Simple example with stdClass object as parameter */
    $wsdl_url  = '';
    $client = new SoapClient($wsdl_url, array('trace' => true));
     
    $parameters = new stdClass();
    $parameters->FromCurrency = 'EUR';
    $parameters->ToCurrency = 'AUD';
     
    $client->ConversionRate($parameters);     
    echo htmlentities($client->__getLastRequest());
     
    /* Example with complex/nested node structure using an array as param*/
    $wsdl_url = "http://yourwsdlfile";
    $client  = new SoapClient($wsdl_url, array('trace' => true));
    $client->YourCall(array(
        'YourContainerNodeName' => array(
            'Level1NodeFoo' => '100',
            'Level1NodeBar' => '100',
            'Subnodes' => array(
                'NodeLevel2' => 'test'
            )
        )
    ));
     
    /* Example with complex/nested node structure using an stdClass as param */
    $wsdl_url = "http://yourwsdlfile";
    $client  = new SoapClient($wsdl_url, array('trace' => true));
    $params = new stdClass();
    $params->YourContainerNodeName = new stdClass();
    $params->YourContainerNodeName->Level1NodeFoo = 100;
    $params->YourContainerNodeName->Level1NodeBar = 100;
    $params->YourContainerNodeName->Subnodes = new stdClass();
    $params->YourContainerNodeName->Subnodes->NodeLevel2 = 'test';
     
    $client->YourCall($params);
     
    /* Example with complex/nested node structure using an stdClass and SoapVars as param */
    $wsdl_url = "http://yourwsdlfile";
    $client  = new SoapClient($wsdl_url, array('trace' => true));
     
    $params = new stdClass();
    $params->YourContainerNodeName = new stdClass();
    $params->YourContainerNodeName->Level1NodeFoo = 100;
    $params->YourContainerNodeName->Level1NodeBar = 100;
    $params->YourContainerNodeName->Subnodes = new stdClass();
    $params->YourContainerNodeName->Subnodes->NodeLevel2 = new SoapVar(3, XSD_INT, 'xsd:int');
    $params->YourContainerNodeName->Subnodes->NodeLevel3 = new SoapVar("<ns1:AdText><![CDATA[hallo<br><br>test]]></ns1:AdText>", XSD_ANYXML);
    $params->YourContainerNodeName->Subnodes->NodeLevel4 = array(
        new SoapVar(1, XSD_INT, 'xsd:int'),
        new SoapVar(2, XSD_INT, 'xsd:int'),
        new SoapVar(3, XSD_INT, 'xsd:int')
    );   
    ?>
    Après avoir compris le mécanisme j'ai pu élaborer ces quelques lignes et ainsi pallier à mon problème

    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
    $arrayStringParamSoap = $this->getArrayStringParamSoap( array("ADD", "OBSERVE", "DELETE") );	
    $paramAction->value =  new SoapVar("<value>".$arrayStringParamSoap."</value>", XSD_ANYXML);
     
    /**
    * Retourne un tableau de variable soap (soapVar) sans provoquer l ajout non volontaire par le serveur soap des balises <BOGUS></BOGUS> | <ENC_STRUCT></ENC_STRUCT>
    * @param string[] $arrayStringParam
    * @return string => chaine formatée prete a etre utilisee comme une SOAPVAR
    */
    private function getArrayStringParamSoap($arrayStringParam)
    {
    	if(!is_array($arrayStringParam))
    	{
    		$arrayStringParam = explode(",", $arrayStringParam);
    	}
     
    	$arraySoapVar = "";
     
    	foreach ($arrayStringParam as $stringParam)
    	{
    		$arraySoapVar .= "<string>".$stringParam."</string>";
    	}
     
    	return $arraySoapVar;
    }

Discussions similaires

  1. Aide requete complexe
    Par Sabine78 dans le forum Access
    Réponses: 9
    Dernier message: 18/04/2006, 21h28
  2. requete complexe
    Par nicohugo dans le forum MS SQL Server
    Réponses: 4
    Dernier message: 30/03/2006, 08h10
  3. Requete complexe
    Par d1g-2-d1g dans le forum Langage SQL
    Réponses: 9
    Dernier message: 02/05/2005, 14h47
  4. Requete complexe
    Par Pfeffer dans le forum Langage SQL
    Réponses: 3
    Dernier message: 18/02/2005, 17h42
  5. requete complexe
    Par Thunder_nico dans le forum Langage SQL
    Réponses: 8
    Dernier message: 07/10/2004, 11h36

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