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. } }
<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>
<?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
your response will be
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
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.
The version doesn't matter. You made me now run your code and I found another bug in your code.
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.
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
Even my own request.xml worked after changing the 'POST' line, so now it's time to make black magic :P
When I have 8000 posts in this forum, I can be the one spotting all the bugs
Independent Consultant/Developer
blog: https://dynamicsuser.net/nav/b/ara3n
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.
In my function I use the following code:
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)?