VAT VIES Webservice

pedgaard
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 :
The request.XML:
The "expected" response.XML
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>
0
Comments
-
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>
0 -
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.0 -
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.0 -
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 :P0 -
you are welcome and hopefully you have better dreams at night.0
-
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.0 -
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';
0 -
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)?/Allan0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions