Précédent   Forum du club des développeurs et IT Pro > PHP > Bibliothèques et frameworks > Services Web
Services Web Forum d'entraide pour les services Web en PHP, qui permettent de créer et de consommer facilement des webservices (génération de WSDL etc.). Exemples : SOAP, NuSOAP, REST, SCA-SDO... Avant de poster -> Cours webservices
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 19/04/2012, 16h38   #1
Abracine
Invité de passage
 
Inscription : novembre 2007
Messages : 4
Détails du profil
Informations forums :
Inscription : novembre 2007
Messages : 4
Points : 0
Points : 0
Par défaut NUSOAP et les Tableaux

Bonjour à tous!

J'aurais besoin d'aide pour l'utilisation de nusoap.

Jusqu'a présent je l'avais utilisé de manière assez basique, avec des paramètres entrée "string" et en sortie des "boolean".

Seuleument maintenant je dois utiliser des tableaux et c'est un peu plus complexes.

Voilà comment marche mon webService:
J'envoie à mon webservice un tableau contenant des adresse mails (par exemple
Code :
$name = array ('toto@toto.com','tata@tata.com','titi@titi.com');
Et en retour, mon webservice doit me renvoyer un autre tableau, en me disant avec un boolean s'il connait l'adresse ou non.
exemple: $res['toto@toto.com'] => 1
$res['tata@tata.com'] =>
$res['titi@titi.com'] => 1


Seuleument voilà, il reçoit bien le tableau d'entrèe, mais celui de sortie est vide, et je galère à trouver d'où vient l'erreur.

mon nusoap server:
Code :
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
 
<?php
// nusoapserver.php
 
require_once('../lib/nusoap.php');
require_once('Auth_V3.php');
 
 
$server = new soap_server();
 
$namespace = "http://xxx/xxx/nusoapserver.php";
$server->wsdl->schemaTargetNamespace = $namespace;
 
//Configure our WSDL
$server->configureWSDL("CheckId");
 
//Complex type paramètre de sortie
$server->wsdl->addComplexType(
        'Contact',
        'complexType',
        'struct',
        'all','',
        array(
//      'email' => array('name' => 'email', 'type' => 'xsd:string'),
        'id' => array('name' => 'id', 'type' => 'xsd:boolean'),
        )
        );
 
$server->wsdl->addComplexType(
        'ContactArray',
        'complexType',
        'array','',
        'SOAP-ENC:Array',
        array(),
        array(
        array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Contact[]')),
        'tns:Contact'
); 
 
//Complex type paramètre d'entrèe
$server->wsdl->addComplexType(
        'email',
        'complexType',
        'struct',
        'all','',
        array(
        'mail' => array('name' => 'email', 'type' => 'xsd:string')
        )
);
 
$server->wsdl->addComplexType(
        'emailArray',
        'complexType',
        'array','',
        'SOAP-ENC:Array',
        array(),
        array(
        array('ref'=>'SOAP-ENC:arrayType','wsdl:arrayType'=>'tns:Contact[]')),
        'tns:email'
);
//Register our Method
$server->register('CheckId',            //nom de la méthode
        array('name'=>'tns:email'),    //paramètre d'entrèe
        array('id'=>'tns:ContactArray'),     //paramètre de sortie
        $namespace,                     //namespace
        false,                          //soapaction
        'rpc',                          //style
        'encoded',                      //use
        'Retourne un 1 si user interne'//Documentation
        );
 
function CheckId($name)
{
$auth = new Auth("server","login","password");
$auth->login();
 
$resultat = $auth->getAccountId($name);
return $resultat;
}
 
// Get our posted data if the service is being consumed
// otherwise leave this data blank.
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
 
// pass our posted data (or nothing) to the soap service
$server->service($POST_DATA);
exit();
 
 
 
?>
Code :
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
 
<?php
// clientnusoap.php
require_once('../lib/nusoap.php');
require_once('Auth_V3.php');
$soapclient = new nusoap_client('http://xxx/xxx/nusoapserver.php?wsdl', true);
 
//Gestion Erreur
$err = $soapclient->getError();
if ($err) {
        echo '<h2>Constructor error</h2><pre>' . $err . '</pre>';
        echo '<h2>Debug</h2><pre>' . htmlspecialchars($client->getDebug(), ENT_QUOTES) . '</pre>';
        exit();
}
 
$name = array('toto@toto.fr','test@test.fr','tata@tata.fr','titi@titi.fr');
$result = $soapclient->call('CheckId',array('name' => $name));
 
if ($soapclient->fault) {
    echo '<h2>Fault</h2><pre>';
    print_r($result);
    echo '</pre>';
} else {
    // Check for errors
    $err = $soapclient->getError();
    if ($err) {
        // Display the error
        echo '<h2>Error</h2><pre>' . $err . '</pre>';
    } else {
        // Display the result
        echo '<h2>Result</h2><pre>';
        print_r($result);
        echo '</pre>';
    }
}
 
// Display the request and response
echo '<h2>Request</h2>';
echo '<pre>' . htmlspecialchars($soapclient->request, ENT_QUOTES) . '</pre>';
echo '<h2>Response</h2>';
echo '<pre>' . htmlspecialchars($soapclient->response, ENT_QUOTES) . '</pre>';
// Display the debug messages
echo '<h2>Debug</h2>';
echo '<pre>' . htmlspecialchars($soapclient->debug_str, ENT_QUOTES) . '</pre>';
 
 
?>
La fonction getAccountId me renvoit le tableau dont j'ai besoin.
Le problème vient je pense de mon complexType, mais pas moyen de trouver la solution!

help
Abracine est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 19h55.


 
 
 
 
Partenaires

Hébergement Web