Bonjour à toutes et à tous,

je cherche à avoir un exemple de consommation d'un web service via Javascript.

Voiçi le lien d'un web service publique et gratuit:

http://www.webservicex.net/CurrencyConvertor.asmx?WSDL

Le problème ici c'est que j'ai cherché sur internet et j'ai pas trouvé beaucoup de résultats sur comment consommer un web service en passant des arguments/paramètres (comme c'est le cas pour le web service cité ci-dessus: FromCurrency / ToCurrency).

J'ai essayé avec ce code, mais rien n'est affiché:

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
 
<script type="text/javascript">
       function soap() {
 
            var xmlhttp = new XMLHttpRequest();
            xmlhttp.open('POST', 'http://www.webservicex.net/CurrencyConvertor.asmx', true);
 
            // build SOAP request
            var sr =
                '<?xml version="1.0" encoding="utf-8"?>' +
                '<soapenv:Envelope ' + 
                    'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
                    'xmlns:api="http://127.0.0.1/Integrics/Enswitch/API" ' +
                    'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
                    'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">' +
                    '<soapenv:Body>' +
                        '<api:some_api_call soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">' +
                            '<FromCurrency xsi:type="xsd:string">TND</FromCurrency>' +
                            '<ToCurrency xsi:type="xsd:string">EUR</ToCurrency>' +
                        '</api:some_api_call>' +
                    '</soapenv:Body>' +
                '</soapenv:Envelope>';
 
            xmlhttp.onreadystatechange = function () {
 
                if (xmlhttp.readyState == 4) {
                    if (xmlhttp.status == 200) {
 
                        alert('done use firebug to see response');
                    }
                }
                if (xmlhttp.readyState == 0) {
                    alert('open() has not been called yet');
                }
 
                if (xmlhttp.readyState == 1) {
                    alert('send() has not been called yet');
                }
 
                if (xmlhttp.readyState == 2) {
                    alert('send() has been called, ...');
                }
 
                if (xmlhttp.readyState == 3) {
                    alert('Interactive - Downloading');
                }
                else
                alert('Consuming Error');
            }
            // Send the POST request
            xmlhttp.setRequestHeader('Content-Type', 'text/xml');
            xmlhttp.send(sr);
            // send request
            // ...
        }
    </script>
NB: J'invoque la méthode post() lorsque j'appuie sur un bouton d'un formulaire.

Comment pourrais-je règler ça?

Merci