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

Bibliothèques et frameworks PHP Discussion :

[Web Service][SOAP] Client en PHP


Sujet :

Bibliothèques et frameworks PHP

  1. #1
    Membre à l'essai
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2009
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Mars 2009
    Messages : 7
    Points : 10
    Points
    10
    Par défaut [Web Service][SOAP] Client en PHP
    Bonjour a tous

    j'ai un web service ecrit en .net et j'aimerai creer un client en php

    le web service est ptotege par login/password.

    lorsque je mets dans le code :
    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
     
    <?php
     
     
            $soapClient = new SoapClient("http://ws.07zr.com/order.asmx?WSDL");
     
            // Prepare SoapHeader parameters
            $sh_param = array(
                        'Username'    =>    '*************',
                        'Password'    =>    '*************');
            $headers = new SoapHeader('http://ws.07zr.com/order.asmx', 'UserCredentials', $sh_param);
     
            // Prepare Soap Client
            $soapClient->__setSoapHeaders(array($headers));
     
            // Setup the RemoteFunction parameters
            $ap_param = array(
                        'amount'     =>    $irow['total_price']);
     
            // Call RemoteFunction ()
            $error = 0;
            try {
                $info = $soapClient->__call("RemoteFunction", array($ap_param));
            } catch (SoapFault $fault) {
                $error = 1;
                print("
                alert('Sorry, blah returned the following ERROR: ".$fault->faultcode."-".$fault->faultstring.". We will now take you back to our home page.');
                window.location = 'main.php';
                ");
            }
     
            if ($error == 0) {       
                $auth_num = $info->RemoteFunctionResult;
     
                if ($auth_num < 0) {
     
     
                    // Setup the OtherRemoteFunction() parameters
                    $at_param = array(
                                'amount'        => $irow['total_price'],
                                'description'    => $description);
     
                    // Call OtherRemoteFunction()
                    $trans = $soapClient->__call("OtherRemoteFunction", array($at_param));
                    $trans_result = $trans->OtherRemoteFunctionResult;
                    } else {
                        // Record the transaction error in the database
     
                    // Kill the link to Soap
                    unset($soapClient);
                }
            }
     
     
     
    ?>
    je reçois l'erreur :
    Warning: SoapClient::SoapClient(http://ws.07zr.com/order.asmx?WSDL) [function.SoapClient-SoapClient]: failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized in C:\wamp\www\WebContent\index.php on line 27

    Warning: SoapClient::SoapClient() [function.SoapClient-SoapClient]: I/O warning : failed to load external entity "http://ws.07zr.com/order.asmx?WSDL" in C:\wamp\www\WebContent\index.php on line 27

    Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://ws.07zr.com/order.asmx?WSDL' in C:\wamp\www\WebContent\index.php:27 Stack trace: #0 C:\wamp\www\WebContent\index.php(27): SoapClient->SoapClient('http://ws.07zr....') #1 {main} thrown in C:\wamp\www\WebContent\index.php on line 27
    est ce que je doit utiliser un proxy ou bien y a t'il une configuration specifique ?

    merci

  2. #2
    Membre régulier
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    84
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 84
    Points : 101
    Points
    101
    Par défaut
    Salut,

    Je sais que j'arrive après la bataille,


    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
    <?php
    
    
            $soapClient = new SoapClient("http://ws.07zr.com/order.asmx?WSDL");
       
            // Prepare SoapHeader parameters
            $sh_param = array(
                        'Username'    =>    '*************',
                        'Password'    =>    '*************');
            $headers = new SoapHeader('http://ws.07zr.com/order.asmx', 'UserCredentials', $sh_param);
       
            // Prepare Soap Client
            $soapClient->__setSoapHeaders(array($headers));
       
            // Setup the RemoteFunction parameters
            $ap_param = array(
                        'amount'     =>    $irow['total_price']);
                       
            // Call RemoteFunction ()
            $error = 0;
            try {
                $info = $soapClient->__call("RemoteFunction", array($ap_param));
            } catch (SoapFault $fault) {
                $error = 1;
                print("
                alert('Sorry, blah returned the following ERROR: ".$fault->faultcode."-".$fault->faultstring.". We will now take you back to our home page.');
                window.location = 'main.php';
                ");
            }
    ?>
    t'as de la chance d'avoir les mêmes variables que dans la doc php ;-)

  3. #3
    Membre régulier
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    84
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 84
    Points : 101
    Points
    101
    Par défaut soap client
    Bonjour,

    dans la même veine que le post précédent, j'ai un soucis depuis 3 jours je tourne en carré (j'en pouvais plus de tourner en rond ...)

    je m'appuie sur l'exemple de la doc PHP,

    j'ai donc mon enveloppe pour poster qui ressemble à ça :

    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
    POST /services/MatterService.asmx HTTP/1.1
    Host: shbo01
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "http://www.elite.com/openapi/GetByNumber"
     
    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Header>
        <user xmlns="http://www.elite.com/openapi" />
      </soap:Header>
      <soap:Body>
        <GetByNumber xmlns="http://www.elite.com/openapi">
          <matterNumber>string</matterNumber>
        </GetByNumber>
      </soap:Body>
    </soap:Envelope>
    et mon appel PHP

    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
     
    <?php
            $soapClient = new SoapClient("http://shbo01/services/MatterService.asmx?WSDL");
     
            // Prepare SoapHeader parameters
            $sh_param = array(
                        'Username'    =>    'my_username',
                        'Password'    =>    'my_password');
            $headers = new SoapHeader('http://www.elite.com/openapi', 'user' , $sh_param);
     
            // Prepare Soap Client
            $soapClient->__setSoapHeaders(array($headers));
     
            // Setup the RemoteFunction parameters
            $ap_param = array(
            						'GetByNumber'     =>    $irow['matterNumber']); 
     
     
            // Call RemoteFunction ()
            $error = 0;
            try {
                $info = $soapClient->GetByNumber($ap_param);
            } catch (SoapFault $fault) {
                $error = 1;
                print("
                ERROR: <br />".$fault->faultcode."<br />-".$fault->faultstring."<br />
                ");
            }
    ?>
    et voilà ...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    ERROR:
    soap:Server
    -Server was unable to process request. ---> Security.CheckUaccess failed to check uaccess table for and column umattm ---> ERROR [07S01] [Microsoft][ODBC SQL Server Driver]Invalid use of default parameter
    à priori je pense à un problème de parametres par defaut qui ne passe pas
    (je pense dans la variable $ap_param)

    qqun aurait-il une idée des paramètres à passer et dans quel ordre?

    (j'ai également essayé avec la methode curl_/curl_setopt ... et j'obtiens la même erreur)

    Thx

    zwaldo

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Juin 2010
    Messages
    49
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2010
    Messages : 49
    Points : 64
    Points
    64
    Par défaut
    Warning: SoapClient::SoapClient() [function.SoapClient-SoapClient]: I/O warning : failed to load external entity "http://ws.07zr.com/order.asmx?WSDL" in C:\wamp\www\WebContent\index.php on line 27

    Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://ws.07zr.com/order.asmx?WSDL' in C:\wamp\www\WebContent\index.php:27 Stack trace: #0 C:\wamp\www\WebContent\index.php(27): SoapClient->SoapClient('http://ws.07zr....') #1 {main} thrown in C:\wamp\www\WebContent\index.php on line 27
    Au vu de ceci, tu as avant tout un problème d'authentification pour obtenir le WSDL pour le passer au constructeur de ton client.

  5. #5
    Membre régulier
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    84
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 84
    Points : 101
    Points
    101
    Par défaut
    Effectivement, je m'en étais rendu compte

    Mais comme je lui passe les identifiants, ainsi que les paramètres du header,

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    $sh_param = array(
                        'Username'    =>    'my_username',
                        'Password'    =>    'my_password');
            $headers = new SoapHeader('http://www.elite.com/openapi', 'user' , $sh_param);
    je pense qu'il lui manque des paramètres ailleurs
    c'est la raison pour laquelle je demandais si qqun avait une idée des paramètres à passer de ma variable $ap_param et dans quel ordre?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    $ap_param = array('GetByNumber'     =>    $irow['matterNumber']);

  6. #6
    Membre du Club
    Profil pro
    Inscrit en
    Juin 2010
    Messages
    49
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Juin 2010
    Messages : 49
    Points : 64
    Points
    64
    Par défaut
    Tu lui passes les identifiants dis-tu, mais tu le fait après l'appel du constructeur.

    Si tu a une erreur 401 au moment de l'exécution de cette ligne :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $soapClient = new SoapClient("http://shbo01/services/MatterService.asmx?WSDL");
    ...tes variables $sh_param et $ap_param ne changeront rien.

    Tu as essayé avec quelque chose comme :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $soapClient = new SoapClient("my_username:my_password@http://shbo01/services/MatterService.asmx?WSDL");
    ?

  7. #7
    Membre à l'essai
    Inscrit en
    Juillet 2006
    Messages
    16
    Détails du profil
    Informations forums :
    Inscription : Juillet 2006
    Messages : 16
    Points : 11
    Points
    11
    Par défaut
    ou quelque chose comme ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    $client = new SoapClient(
    	    'http://shbo01/services/MatterService.asmx?WSDL',
    	    array('login' => 'monlogin', 'password' => 'monpass')
        );

Discussions similaires

  1. Utiliser un objet dans un Web Service Soap Client
    Par benny-blanco dans le forum Services Web
    Réponses: 1
    Dernier message: 19/04/2012, 10h23
  2. Web Service Soap Client
    Par benny-blanco dans le forum Windows Phone
    Réponses: 1
    Dernier message: 08/04/2012, 01h25
  3. [Web Service][SOAP] Client Web Service en PHP5
    Par bm_belgacem dans le forum Bibliothèques et frameworks
    Réponses: 6
    Dernier message: 07/05/2008, 19h03
  4. [Web Service][SOAP] NuSOAP avec PHP
    Par BRAUKRIS dans le forum Bibliothèques et frameworks
    Réponses: 2
    Dernier message: 15/06/2007, 19h29
  5. [Web Service][SOAP] Client soap PHP et C#
    Par zulot dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 19/04/2007, 11h53

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