VAT VIES Webservice

pedgaardpedgaard Member Posts: 24
Hey,

I am quite new to the forum, but I believe I have just about read every single post regarding webservices on the forum, without finding the answer to my problem.
So I decided to post a new thread about how to validate a EU vat number against the european database in VIES.

Can anyone give me a hint to why the following codeunit doesn't work, I am also quite unexperienced in the field.
To try and debug it, I have used the exact same request.xml file (attached further below) in a test in XMLspy, and I get a proper response.xml (attached further below) back.
But in Navision, I do get the correct status back (200 = Success I think), but the response.xml is a 11kb file with the entire contents of the wdsl such as functions and general information.

It is driving my mind crazy and I actually woke up this morning thinking I had solved it during the night...but it was only a dream! ](*,)

I am trying to use the checkVat function provied by the:
http://ec.europa.eu/taxation_customs/vi ... rvice.wsdl



The Codeunit :
OBJECT Codeunit 57777 Vies Webservice
{
  OBJECT-PROPERTIES
  {
    Date=14-03-11;
    Time=12:38:00;
    Modified=Yes;
    Version List=1.00;
  }
  PROPERTIES
  {
    OnRun=BEGIN
            ValidateVatNo
          END;

  }
  CODE
  {

    PROCEDURE ValidateVatNo@1000000001();
    VAR
      lXmlHttp@1000000000 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 5.0:{F6D90F16-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v5.0'.XMLHTTP";
      lXmlDoc@1000000001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 5.0:{F6D90F11-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v5.0'.DOMDocument";
    BEGIN
      CREATE(lXmlDoc);
      lXmlDoc.async := FALSE;
      lXmlDoc.load('C:\request.xml');

      CREATE(lXmlHttp);
      lXmlHttp.open('POST','http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl', 0);
      lXmlHttp.setRequestHeader('Content-type', 'text/xml; charset=utf-8');
      lXmlHttp.setRequestHeader('SOAPAction','urn:ec.europa.eu:taxud:vies:services:checkVat:types');
      lXmlHttp.send(lXmlDoc);
      lXmlDoc.load(lXmlHttp.responseXML);
      lXmlDoc.save('C:\response.xml');

      IF lXmlHttp.status = 200 THEN
        MESSAGE('%1', lXmlDoc.documentElement.selectSingleNode('Valid').text)
      ELSE
        MESSAGE('%1', lXmlHttp.status);
    END;

    BEGIN
    {
      Function to validate a VAT number to VIES database :
      'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl'
    }
    END.
  }
}


The request.XML:
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<SOAP-ENV:Body>
		<checkVat xmlns="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
			<countryCode>DK</countryCode>
			<vatNumber>25313763</vatNumber>
		</checkVat>
	</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

The "expected" response.XML
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
	<soapenv:Body>
		<urn:checkVatResponse xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
			<urn:countryCode>DK</urn:countryCode>
			<urn:vatNumber>25313763</urn:vatNumber>
			<urn:requestDate>2011-03-14+01:00</urn:requestDate>
			<urn:valid>true</urn:valid>
			<urn:name>ARLA FOODS AMBA</urn:name>
			<urn:address>SØNDERHØJ 14 
 
8260 VIBY J</urn:address>
		</urn:checkVatResponse>
	</soapenv:Body>
</soapenv:Envelope>

Comments

  • ara3nara3n Member Posts: 9,256
    your request.xml should look like this

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
       <soapenv:Header/>
       <soapenv:Body>
          <urn:checkVat>
             <urn:countryCode>DK</urn:countryCode>
             <urn:vatNumber>25313763</urn:vatNumber>
          </urn:checkVat>
       </soapenv:Body>
    </soapenv:Envelope>
    

    your response will be
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
       <soapenv:Body>
          <urn:checkVatResponse xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
             <urn:countryCode>DK</urn:countryCode>
             <urn:vatNumber>25313763</urn:vatNumber>
             <urn:requestDate>2011-03-14+01:00</urn:requestDate>
             <urn:valid>true</urn:valid>
             <urn:name>ARLA FOODS AMBA</urn:name>
             <urn:address>SØNDERHØJ 14 
     
    8260 VIBY J</urn:address>
          </urn:checkVatResponse>
       </soapenv:Body>
    </soapenv:Envelope>
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • pedgaardpedgaard Member Posts: 24
    Thanks for the reply, but changing the request.xml to your suggestion did not change anything on my Windows 7 + Windows XP machine in NAV 5.0 runtime 2009 SP!.

    Did you manage with the above codeunite, and if so, on what versions of NAV - now I am jealous :)

    Maybe it is something really silly that I am doing wrong, I have copied your message code into an empty notepad, saved as request.xml, and fired up the codeunit.
  • ara3nara3n Member Posts: 9,256
    Lol.

    The version doesn't matter. You made me now run your code and I found another bug in your code.
    CREATE(lXmlDoc);
    lXmlDoc.async := FALSE;
    lXmlDoc.load('C:\Temp\request.xml');
    
    CREATE(lXmlHttp);
    lXmlHttp.open('POST','http://ec.europa.eu/taxation_customs/vies/services/checkVatService', 0);
    lXmlHttp.setRequestHeader('Content-type', 'text/xml; charset=utf-8');
    lXmlHttp.setRequestHeader('SOAPAction','');
    lXmlHttp.send(lXmlDoc);
    lXmlDoc.load(lXmlHttp.responseXML);
    lXmlDoc.save('C:\Temp\response.xml');
    
    IF lXmlHttp.status = 200 THEN
      MESSAGE('%1', lXmlDoc.documentElement.selectSingleNode('Valid').text)
    ELSE
      MESSAGE('%1', lXmlHttp.status);
    

    I've changed the POST line.

    Also you'll get your response, but lXmlDoc.documentElement.selectSingleNode('Valid').text still errors out. You need put eh valid path.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • pedgaardpedgaard Member Posts: 24
    edited 2011-03-15
    Thank you - that worked \:D/
    Even my own request.xml worked after changing the 'POST' line, so now it's time to make black magic :P
  • pedgaardpedgaard Member Posts: 24
    ara3n wrote:
    Lol.

    The version doesn't matter. You made me now run your code and I found another bug in your code.


    When I have 8000 posts in this forum, I can be the one spotting all the bugs :D
  • ara3nara3n Member Posts: 9,256
    you are welcome and hopefully you have better dreams at night.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • undercoverundercover Member Posts: 3
    Hello,

    I would really upreciate if you tell me how you solved the error with the path from
    lXmlDoc.documentElement.selectSingleNode('Valid').

    Everything worked for me but I don't know how to solve this issue.

    thanks a lot.
  • BigBroBigBro Member Posts: 8
    In case somebody is still interested, the path is "//soapenv:Body/urn:checkVatResponse/urn:valid" :

    In my function I use the following code:
      s := '';
      lXmlNode := lXmlDoc.documentElement.selectSingleNode('//soapenv:Body/urn:checkVatResponse/urn:valid');
      IF NOT ISCLEAR(lXmlNode) THEN BEGIN
        s := lXmlNode.text;
        Result := s = 'true';
    
  • ASK_ITGASK_ITG Member Posts: 30
    Hi all,

    Does anyone have the opportunity of uploading a .FOB-file with the codeunits needed for calling the Webservice in Classic Client, and the functions used for creating the nessecary XML-files (requests)?
    /Allan
Sign In or Register to comment.