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

XML/XSL et SOAP Discussion :

SOAP Webservice VIES


Sujet :

XML/XSL et SOAP

  1. #1
    Membre confirmé
    Inscrit en
    Février 2011
    Messages
    465
    Détails du profil
    Informations forums :
    Inscription : Février 2011
    Messages : 465
    Points : 549
    Points
    549
    Par défaut SOAP Webservice VIES
    Bonjour,

    Le site VIES des Communautés Européennes permet de vérifier des numéros de TVA.
    Vous pouvez ouvrir Internet Explorer à l'adresse http://ec.europa.eu/taxation_customs...atRequest.html et vous l'utilisez manuellement ou vous utilisez le webservice prévu à cet effet.
    J'essaye d'utiliser le WebService SOAP dont voici le wsdl mais je ne parviens pas à résoudre mon erreur parce que je ne maîtrise pas bien les concepts du wsdl et l'enveloppe.

    Voici mon code (c'est du VBA Microsoft Office) :
    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
    Function VIES()
    'utilise la référence "Micorosoft XML, V6.0"
    Dim strResponseText As String
    Dim strURL As String
    Dim strEnv As String
    Dim xmlhtp As MSXML2.XMLHTTP60
     
    'The URL address of the wsdl
    strURL = "http://ec.europa.eu/taxation_customs/vies/checkVatTestService.wsdl"       'TEST wsdl
    'strURL = "http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl"           'PROD beware of blacklisting !!
     
     
    ' we create our SOAP envelope for submission to the Web Service
    strEnv = "<?xml version=""1.0"" encoding=""utf-8""?>"
    'je reprends tous les elements du début(definition) du wsdl :
    strEnv = strEnv & "<soapenv:Envelope targetNamespace=""urn:ec.europa.eu:taxud:vies:services:checkVat"" "
    strEnv = strEnv & "xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" "
    strEnv = strEnv & "xmlns:apachesoap=""http://xml.apache.org/xml-soap"" "
    strEnv = strEnv & "xmlns:impl=""urn:ec.europa.eu:taxud:vies:services:checkVat"" "
    strEnv = strEnv & "xmlns:soapenc=""http://schemas.xmlsoap.org/soap/encoding/"" "
    strEnv = strEnv & "xmlns:tns1=""urn:ec.europa.eu:taxud:vies:services:checkVat:types"" "
    strEnv = strEnv & "xmlns:wsdl=""http://schemas.xmlsoap.org/wsdl/"" "
    strEnv = strEnv & "xmlns:wsdlsoap=""http://schemas.xmlsoap.org/wsdl/soap/"" "
    strEnv = strEnv & "xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" >"
    strEnv = strEnv & "  <soapenv:Header/>"
    strEnv = strEnv & "  <soapenv:Body>"
    strEnv = strEnv & "   <checkVat>"
    strEnv = strEnv & "    <countryCode>LU</countryCode>"
    strEnv = strEnv & "    <vatNumber>200</vatNumber>"
    strEnv = strEnv & "   </checkVat>"
    strEnv = strEnv & "  </soapenv:Body>"
    strEnv = strEnv & "</soapenv:Envelope>"
     
     
    strURL = "http://ec.europa.eu/taxation_customs/vies/services/checkVatTestService"
    Set xmlhtp = New MSXML2.XMLHTTP60
     
    xmlhtp.Open "POST", strURL, False         'POST, OPEN, GET : Always use uppercase as some servers ignore lowercase HTTP verbs
     
    xmlhtp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
    xmlhtp.setRequestHeader "soapAction", "checkVatRequest"
     
    xmlhtp.send strEnv
    strResponseText = xmlhtp.responseText
     
    Debug.Print strResponseText
     
    Set xmlhtp = Nothing
     
    End Function
    En clair, l'enveloppe que j'envoie est
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    <soapenv:Envelope targetNamespace="urn:ec.europa.eu:taxud:vies:services:checkVat" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="urn:ec.europa.eu:taxud:vies:services:checkVat" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="urn:ec.europa.eu:taxud:vies:services:checkVat:types" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    	<soapenv:Header/>
    	<soapenv:Body>
    		<checkVat>
    			<countryCode>LU</countryCode>
    			<vatNumber>200</vatNumber>
    		</checkVat>
    	</soapenv:Body>
    </soapenv:Envelope>
    mais la réponse que je reçois me déçoit :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
      <soap:Fault>
        <faultcode>soap:Client</faultcode>
        <faultstring>Unexpected wrapper element checkVat found.   Expected {urn:ec.europa.eu:taxud:vies:services:checkVat:types}checkVat.</faultstring>
      </soap:Fault>
    </soap:Body>
    </soap:Envelope>
    Je ne comprends pas cette réponse.

    checkVat est bien une opération du Webservice et checkVat doit contenir 2 éléments, dans l'ordre: countryCode puis vatNumber.

    Il y a donc quelque chose d'autre qui coince.

    Merci pour vos explications.

  2. #2
    Membre émérite Avatar de tsuji
    Inscrit en
    Octobre 2011
    Messages
    1 558
    Détails du profil
    Informations forums :
    Inscription : Octobre 2011
    Messages : 1 558
    Points : 2 736
    Points
    2 736
    Par défaut
    [1] Dans la construction de strEnv, au lieu de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    targetNamespace=""urn:ec....""
    , remplacez-le par ceci:
    Code vb : Sélectionner tout - Visualiser dans une fenêtre à part
    xmlns=""urn:ec....""
    qui est le namespace par defaut de checkVat et ses enfants.
    [2] La ligne de setRequestHeader la valeur de soapAction doit etre vide:
    Code vb : Sélectionner tout - Visualiser dans une fenêtre à part
    xmlhtp.setRequestHeader "soapAction", """"""

    ps: Je suis en mobile, donc je ne peux tres elaborer.

  3. #3
    Membre confirmé
    Inscrit en
    Février 2011
    Messages
    465
    Détails du profil
    Informations forums :
    Inscription : Février 2011
    Messages : 465
    Points : 549
    Points
    549
    Par défaut
    OK. Merci beaucoup pour le coup de main.

    Les deux corrections ne sont pas anodines puisqu'elles me donnent un autre résultat:

    Pour le moment, J'ai ceci :
    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
    Function VIES()
    'utilise la référence "Micorosoft XML, V6.0"
    Dim strResponseText As String
    Dim strURL As String
    Dim strEnv As String
    Dim xmlhtp As MSXML2.XMLHTTP60
     
    'The URL address of the wsdl
    strURL = "http://ec.europa.eu/taxation_customs/vies/checkVatTestService.wsdl"       'TEST wsdl
    'strURL = "http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl"           'PROD beware of blacklisting !!
     
     
    ' we create our SOAP envelope for submission to the Web Service
    strEnv = "<?xml version=""1.0"" encoding=""utf-8""?>"
    'je reprends tous les elements du début(definition) du wsdl :
    strEnv = strEnv & "<soapenv:Envelope xmlns""urn:ec.europa.eu:taxud:vies:services:checkVat"" "    'xmlns au lieu de targetNamespace
    strEnv = strEnv & "xmlns:tns1=""urn:ec.europa.eu:taxud:vies:services:checkVat:types"" "
    strEnv = strEnv & "xmlns:soapenc=""http://schemas.xmlsoap.org/soap/encoding/"" "
    strEnv = strEnv & "xmlns:impl=""urn:ec.europa.eu:taxud:vies:services:checkVat"" "
    strEnv = strEnv & "xmlns:apachesoap=""http://xml.apache.org/xml-soap"" "
    strEnv = strEnv & "xmlns:wsdl=""http://schemas.xmlsoap.org/wsdl/"" "
    strEnv = strEnv & "xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" "
    strEnv = strEnv & "xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" >"
    strEnv = strEnv & "xmlns:wsdlsoap=""http://schemas.xmlsoap.org/wsdl/soap/"" "
     
    strEnv = strEnv & "  <soapenv:Header/>"
    strEnv = strEnv & "  <soapenv:Body>"
    strEnv = strEnv & "   <checkVat>"
    strEnv = strEnv & "    <countryCode>FI</countryCode>"
    strEnv = strEnv & "    <vatNumber>202</vatNumber>"
    strEnv = strEnv & "   </checkVat>"
    strEnv = strEnv & "  </soapenv:Body>"
    strEnv = strEnv & "</soapenv:Envelope>"
     
    strURL = "http://ec.europa.eu/taxation_customs/vies/services/checkVatTestService"
    Set xmlhtp = New MSXML2.XMLHTTP60
     
    xmlhtp.Open "POST", strURL, False         'POST, OPEN, GET : Always use uppercase as some servers ignore lowercase HTTP verbs
     
    xmlhtp.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
    xmlhtp.setRequestHeader "soapAction", ""
     
    xmlhtp.send strEnv
    strResponseText = xmlhtp.responseText
     
     
    Debug.Print strResponseText
     
    Set xmlhtp = Nothing
     
     
    End Function
    Donc l'enveloppe envoyée est ceci :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <?xml version="1.0" encoding="utf-8"?>
    <soapenv:Envelope xmlns"urn:ec.europa.eu:taxud:vies:services:checkVat" xmlns:tns1="urn:ec.europa.eu:taxud:vies:services:checkVat:types" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:impl="urn:ec.europa.eu:taxud:vies:services:checkVat" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" >
      <soapenv:Header/>
      <soapenv:Body>
       <checkVat>
        <countryCode>FI</countryCode>
        <vatNumber>202</vatNumber>
       </checkVat>
      </soapenv:Body>
    </soapenv:Envelope>
    Mais cela donne ce message d'erreur :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <soap:Fault>
          <faultcode>soap:Server</faultcode>
          <faultstring>Couldn't parse stream.</faultstring>
        </soap:Fault>
      </soap:Body>
    </soap:Envelope>
    Je continue à chercher. Je ne comprends toujours pas comment rédiger mon enveloppe en fonction du wsdl.

    Merci.

  4. #4
    Membre émérite Avatar de tsuji
    Inscrit en
    Octobre 2011
    Messages
    1 558
    Détails du profil
    Informations forums :
    Inscription : Octobre 2011
    Messages : 1 558
    Points : 2 736
    Points
    2 736
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    strEnv = strEnv & "<soapenv:Envelope xmlns""urn:ec.europa.eu:taxud:vies:services:checkVat"" "    'xmlns au lieu de targetNamespace
    xmlns= tout court et avec un sign d'égalité et l'url avec la particule :types
    Code vb : Sélectionner tout - Visualiser dans une fenêtre à part
    strEnv = strEnv & "<soapenv:Envelope xmlns=""urn:ec.europa.eu:taxud:vies:services:checkVat:types"" "
    Cela signifie un namespace par défaut et il a un impact significatif sur l'interprétation de checkVat et ses enfants.

  5. #5
    Membre confirmé
    Inscrit en
    Février 2011
    Messages
    465
    Détails du profil
    Informations forums :
    Inscription : Février 2011
    Messages : 465
    Points : 549
    Points
    549
    Par défaut
    Oui, cela change tout !
    il manquait aussi un = à la ligne précédente.

    Maintenant, ça marche. Je reçois une réponse qui me permets d'avancer.
    Un tout grand merci pour le coup de pouce !

  6. #6
    Membre confirmé
    Inscrit en
    Février 2011
    Messages
    465
    Détails du profil
    Informations forums :
    Inscription : Février 2011
    Messages : 465
    Points : 549
    Points
    549
    Par défaut
    Ooups.. : ".. qui me permet...."
    Ce genre de faute de grammaire pique aux yeux et après l'aide que le forum m'a offerte, je ne voudrais pas faire souffrir votre vision.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Web Service][SOAP] webservice : retour d'un tableau au client
    Par Florent08800 dans le forum Bibliothèques et frameworks
    Réponses: 7
    Dernier message: 05/05/2012, 14h54
  2. Aide création soap webservice
    Par Florent08800 dans le forum Flash
    Réponses: 7
    Dernier message: 22/01/2007, 18h23
  3. [Web Service][SOAP] Webservice Nusoap : page blanche
    Par Harry dans le forum Bibliothèques et frameworks
    Réponses: 2
    Dernier message: 11/01/2007, 17h37
  4. [Web Service][SOAP] Webservices : Comment faire ?
    Par juliotte dans le forum Bibliothèques et frameworks
    Réponses: 6
    Dernier message: 18/12/2006, 17h50
  5. Compo HTTP et client SOAP webservice ?
    Par Bruno13 dans le forum Web & réseau
    Réponses: 34
    Dernier message: 03/04/2006, 19h09

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