Jump to content

Recommended Posts

Posted

Here are some information:

http://ec.europa.eu/taxation_customs/vies/faq.html?locale=en
http://ec.europa.eu/taxation_customs/vies/vatRequest.html?locale=en

and this
http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl

and my questions:

1. Has anyone automate the verification process using this service ?
2. Is this wsdl file is sufficient documentation to establish adequate solution, or you have to have additional documentation / specifications derived from this organization?

 

mLipok

ps.

This be the first time when I will try to use SOAP so I'm fledgling in this matter.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

I would be grateful if someone who knows this stuff just said something about (will direct me to the right path), the rest I prefer to read through, some think, and come back with further questions, this way I better assimilate knowledge.

I am glad that there are others interested because the discussion will be more interesting.

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

I use it in my work.

I created function using VIES / SOAP and it works fine for me. In 2010 they changed URLs so I have to modify my function.

Here are general useful SOAP & AutoIt links:

http://stackoverflow.com/questions/124269/simplest-soap-example

***

Here is simplified my function in PowerBuilder syntax (very similar to AutoIt),

comments are in Czech language:

global function string uf_c_kontrola_dic (string dic, ref s_c_kontrola_dic str_dic);
// pri chybe vrati chybove hlaseni
// pri OK vrati prazdny retezec a naplni strukturu

s_sys_http_output output
int i
string ls_pom, ls_xml, ls_xml_data, ls_header, stat, ls_url, ls_action

// na vstupu bude DIC vcetne statu, ale zde se musi rozlozit na stat a samotne cislo dic
stat = Upper(Left(dic,2)) // country
dic = Mid(dic,3) // VAT

ls_url = 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService;checkVat'

ls_pom = uf_parse_string(ls_url, ';')
ls_action = ls_url // nyni uz nevyuzity - not used now
ls_url = ls_pom

ls_xml_data = '<?xml version="1.0" encoding="utf-8"?> ' + &
                  '<soap:Envelope ' + &
                  'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ' + &
                  'xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types"> ' + &
                  '<soap:Body> ' + &
                  '<urn:checkVat> ' + &
                  '  <urn:countryCode>#stat</urn:countryCode> ' + &
                  '  <urn:vatNumber>#dic</urn:vatNumber> ' + &
                  '</urn:checkVat></soap:Body></soap:Envelope>'

ls_xml_data = uf_replaceall(ls_xml_data, '#stat', stat)
ls_xml_data = uf_replaceall(ls_xml_data, '#dic', dic)

ls_header = 'Content-Type~tText/xml~n' + &
                'SOAPAction~t""'

i = uf_sys_http_prikaz('POST',ls_url,'','',ls_header,ls_xml_data,'','','',output) // wrapper for WinHttp.WinHttpRequest.5.1
IF i <> 0 THEN    RETURN 'Chyba při odesílání HTTP požadavku.~nčíslo chyby: ' + string(i)
//    nf_msgupo(output.status + '~n' + output.statustext + '~n~n' + output.allresponseheaders + '~n~n' + output.responsetext)

// pokud nedojde k chybe obsahuje output.responsetext XML data s vysledkem
// v pripade chyby obsahuje output.responsetext HTML popis chyby
ls_xml = output.responsetext

// POZOR: XML obsahuje ceske znaky zakodovane pomoci HTML, napr: Anton&#xED;n
ls_xml = uf_sys_conv_html_1250(ls_xml)

// HTTP status OK je 200
IF output.status <> '200' THEN
    ls_pom = uf_string_between(ls_xml, '<faultstring>','</faultstring>')
    IF ls_pom <> '' THEN // chyba ze SOAP serveru (v XML tvaru)
        RETURN 'Chyba v XML souboru.~npopis chyby: ' + ls_pom
    ELSE // zrejme chyba HTTP (v HTML tvaru)
        RETURN 'Chyba při odesílání HTTP požadavku.~nstatus text: ' + output.statustext + '~nresponse text: ' + uf_sys_html2txt(output.responsetext)
    END IF
END IF

IF Left(ls_xml,5) = '<?xml' THEN
    str_dic.stat = stat
    str_dic.dic = dic
    str_dic.name = uf_string_between(ls_xml, '<urn:name>','</urn:name>')
    str_dic.address = uf_string_between(ls_xml, '<urn:address>','</urn:address>')
    str_dic.valid = uf_string_between(ls_xml, '<urn:valid>','</urn:valid>')
ELSEIF LEFT(ls_xml,14) = '<soap:Envelope' THEN
    str_dic.stat = stat
    str_dic.dic = dic
    str_dic.name = uf_string_between(ls_xml, '<name>','</name>')
    str_dic.address = uf_string_between(ls_xml, '<address>','</address>')
    str_dic.valid = uf_string_between(ls_xml, '<valid>','</valid>')
ELSE
    RETURN 'Chyba v XML souboru.~nsoubor nemá správnou XML hlavičku~n~n' + ls_xml // v pripade chybne URL muze vratit HTML s chybou
END IF

RETURN ''
end function

 

Edited by Zedna
Posted

What uf_parse_string function doing ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

For now I have this (not working yet) script:

#include <String.au3>

Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

Local $o_str_dic
uf_c_kontrola_dic('PL123456789123', $o_str_dic);

Func uf_c_kontrola_dic($sDic, ByRef $o_str_dic);
    ; pri chybe vrati chybove hlaseni
    ; pri OK vrati prazdny retezec a naplni strukturu

    Local $oOutput
    Local $i
    Local $s_ls_pom, $s_ls_xml, $s_ls_xml_data, $s_ls_header, $sStat, $s_ls_url, $s_ls_action

    ; na vstupu bude DIC vcetne statu, ale zde se musi rozlozit na stat a samotne cislo dic
    $sStat = StringUpper(StringLeft($sDic, 2)) ; country
    $sDic = StringMid($sDic, 3) ; VAT

    $s_ls_url = 'http:;ec.europa.eu/taxation_customs/vies/services/checkVatService;checkVat'

    $s_ls_pom = uf_parse_string($s_ls_url, ';')
    $s_ls_action = $s_ls_url ; nyni uz nevyuzity - not used now
    $s_ls_url = $s_ls_pom

    $s_ls_xml_data = '<?xml version="1.0" encoding="utf-8"?> ' & _
            '<soap:Envelope ' & _
            'xmlns:soap="http:;schemas.xmlsoap.org/soap/envelope/" ' & _
            'xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types"> ' & _
            '<soap:Body> ' & _
            '<urn:checkVat> ' & _
            '  <urn:countryCode>#$sStat</urn:countryCode> ' & _
            '  <urn:vatNumber>#$sDic</urn:vatNumber> ' & _
            '</urn:checkVat></soap:Body></soap:Envelope>'

    $s_ls_xml_data = StringReplace($s_ls_xml_data, '#$sStat', $sStat)
    $s_ls_xml_data = StringReplace($s_ls_xml_data, '#$sDic', $sDic)

    $s_ls_header = _
            'Content-Type' & @TAB & 'Text/xml' & @CRLF & _
            'SOAPAction' & @TAB & '""'

;~  $i = uf_sys_http_prikaz('POST', $s_ls_url, '', '', $s_ls_header, $s_ls_xml_data, '', '', '', $oOutput) ; wrapper for WinHttp.WinHttpRequest.5.1
    $i = _SOAP_Api_Sender('POST', $s_ls_url, $s_ls_header, $s_ls_xml_data, $oOutput) ; wrapper for WinHttp.WinHttpRequest.5.1

    If $i <> 0 Then
        Return 'Chyba při odesílání HTTP požadavku.' & @CRLF & 'číslo chyby: ' & String($i)
    EndIf
    ;    nf_msgupo($oOutput.status + '~n' + $oOutput.statustext + '~n~n' + $oOutput.allresponseheaders + '~n~n' + $oOutput.responsetext)

    ; pokud nedojde k chybe obsahuje $oOutput.responsetext XML data s vysledkem
    ; v pripade chyby obsahuje $oOutput.responsetext HTML popis chyby
    $s_ls_xml = $oOutput.responsetext

    ; POZOR: XML obsahuje ceske znaky zakodovane pomoci HTML, napr: Anton&#xED;n
;~ $s_ls_xml = uf_sys_conv_html_1250($s_ls_xml)

    ; HTTP status OK je 200
    If $oOutput.status <> '200' Then
        $s_ls_pom = _StringBetween($s_ls_xml, '<faultstring>', '</faultstring>')
        If $s_ls_pom <> '' Then ; chyba ze SOAP serveru (v XML tvaru)
            Return 'Chyba v XML souboru.~npopis chyby: ' & $s_ls_pom
        Else ; zrejme chyba HTTP (v HTML tvaru)
;~          Return 'Chyba při odesílání HTTP požadavku.~nstatus text: ' + $oOutput.statustext + '~nresponse text: ' + uf_sys_html2txt($oOutput.responsetext)
            Return 'Chyba při odesílání HTTP požadavku.' & @CRLF & 'status text: ' & $oOutput.statustext & @CRLF & 'response text: ' & $oOutput.responsetext
        EndIf
    EndIf

    If StringLeft($s_ls_xml, 5) = '<?xml' Then
        MsgBox(0, '$s_ls_xml', $s_ls_xml)

        #cs
            $o_str_dic.stat = $sStat
            $o_str_dic.dic = $sDic
            $o_str_dic.name = _StringBetween($s_ls_xml, '<urn:name>', '</urn:name>')
            $o_str_dic.address = _StringBetween($s_ls_xml, '<urn:address>', '</urn:address>')
            $o_str_dic.valid = _StringBetween($s_ls_xml, '<urn:valid>', '</urn:valid>')

        #CE
    ElseIf StringLeft($s_ls_xml, 14) = '<soap:Envelope' Then
        MsgBox(0, '$s_ls_xml', $s_ls_xml)

        #CS
            $o_str_dic.stat = $sStat
            $o_str_dic.dic = $sDic
            $o_str_dic.name = _StringBetween($s_ls_xml, '<name>', '</name>')
            $o_str_dic.address = _StringBetween($s_ls_xml, '<address>', '</address>')
            $o_str_dic.valid = _StringBetween($s_ls_xml, '<valid>', '</valid>')

        #CE
    Else
        Return 'Chyba v XML souboru.' & @CRLF & 'nsoubor nemá správnou XML hlavičku' & @CRLF & @CRLF & $s_ls_xml ; v pripade chybne URL muze vratit HTML s chybou
    EndIf

    Return ''
EndFunc   ;==>uf_c_kontrola_dic


Func _SOAP_Api_Sender($sType, $s_ls_url, $s_ls_header, $s_ls_xml_data, ByRef $oOutput)
    $objHTTP = ObjCreate("Microsoft.XMLHTTP")
    $objReturn = ObjCreate("Msxml2.DOMdocument.3.0")

    ; Create the SOAP Envelope
    $strEnvelope = $s_ls_xml_data

    ; Set up to post to our local server
    $objHTTP.open("post", $s_ls_url, False)

    ; Set a standard SOAP/ XML header for the content-type
    $objHTTP.setRequestHeader("Content-Type", "text/xml")
;~  $objHTTP.setRequestHeader("Content-Type", $s_ls_header)

    ; Set a header for the method to be called
;~  $objHTTP.setRequestHeader("SOAPMethodName", "urn:myserver/soap:TaxCalculator#getsalestax")
    $objHTTP.setRequestHeader("SOAPAction", "")

    ConsoleWrite("Content of the Soap envelope : " & @CR & $strEnvelope & @CR & @CR)

    ; Make the SOAP call
    $objHTTP.send($strEnvelope)
    $oOutput = $objHTTP

EndFunc   ;==>_SOAP_Api_Sender


; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Here is simplified wrapper for WinHttp.WinHttpRequest.5.1 (function uf_sys_http_prikaz) used in my previous example

global function integer uf_sys_http_prikaz (readonly string prikaz, readonly string url, readonly string jmeno, readonly string heslo, string hlavicka, readonly string data, ref s_sys_http_output output);

// prikaz - GET/PUT/POST/...
// url - https://www.server.com:port/adresar
// hlavicka - seznam vsech udaju hlavicky ve tvaru: nazev1~thodnota1~nnazev2~thodnota2~nnazev3~thodnota3

// pri chybe vrati zaporny chybovy kod
// pri OK vrati 0

INTEGER HTTPREQUEST_PROXYSETTING_DEFAULT = 0
INTEGER HTTPREQUEST_PROXYSETTING_PRECONFIG = 0
INTEGER HTTPREQUEST_PROXYSETTING_DIRECT = 1
INTEGER HTTPREQUEST_PROXYSETTING_PROXY = 2 
INTEGER HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
INTEGER HTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1

string ls_hlavicka_cast, ls_nazev, ls_hodnota
integer result

OLEObject oHttpRequest
oHttpRequest = CREATE OLEObject
result = oHttpRequest.ConnectToNewObject("WinHttp.WinHttpRequest.5.1")

oHttpRequest.Open(prikaz, url, False)
if jmeno <> '' then oHttpRequest.SetCredentials(jmeno, heslo, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER) // name,password

if hlavicka <> '' then // header
    // pozn: udaje hlavicky se musi nastavit po jednom
    DO WHILE hlavicka <> ''
        ls_hlavicka_cast = uf_parse_string(hlavicka,'~n') // nazev1~thodnota1
        ls_nazev = uf_parse_string(ls_hlavicka_cast,'~t')
        ls_hodnota = ls_hlavicka_cast
        oHttpRequest.SetRequestHeader(ls_nazev, ls_hodnota)
    LOOP
end if

oHttpRequest.Send(data)

output.Status = string(oHttpRequest.Status) 
output.StatusText = oHttpRequest.StatusText
output.AllResponseHeaders = oHttpRequest.GetAllResponseHeaders()
output.ResponseText = oHttpRequest.ResponseText

oHttpRequest.DisconnectObject()
DESTROY oHttpRequest
return 0
end function

 

Edited by Zedna
  • 3 months later...
Posted (edited)

I'm back to this.

And have some problems:

#include <String.au3>
#include <array.au3>

Global Enum _
        $__g_iOutput_Status, _
        $__g_iOutput_StatusText, _
        $__g_iOutput_AllResponseHeaders, _
        $__g_iOutput_ResponseText, _
        $__g_iOutput_ENUMCOUNTER

Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")

Local $o_str_dic
; check TeamViewer GmbH NIP
MsgBox(0, '', uf_c_kontrola_dic('DE245838579', $o_str_dic))

Func uf_c_kontrola_dic($sDic, ByRef $o_str_dic)
    ; pri chybe vrati chybove hlaseni
    ; pri OK vrati prazdny retezec a naplni strukturu

    Local $aOutput[$__g_iOutput_ENUMCOUNTER]
    Local $i
    Local $spom, $sXML, $sXML_data, $sHeader, $sStat, $sURL, $saction

    ; na vstupu bude DIC vcetne statu, ale zde se musi rozlozit na stat a samotne cislo dic
    $sStat = StringUpper(StringLeft($sDic, 2)) ; country
    $sDic = StringMid($sDic, 3) ; VAT

    $sURL = 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService;checkVat'

    $spom = StringSplit($sURL, ';')[1]
    $saction = $sURL ; nyni uz nevyuzity - not used now
    $sURL = $spom

    $sXML_data = '<?xml version="1.0" encoding="utf-8"?> ' & _
            '<soap:Envelope ' & _
            'xmlns:soap="http:;schemas.xmlsoap.org/soap/envelope/" ' & _
            'xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types"> ' & _
            '<soap:Body> ' & _
            '<urn:checkVat> ' & _
            '  <urn:countryCode>#$sStat</urn:countryCode> ' & _
            '  <urn:vatNumber>#$sDic</urn:vatNumber> ' & _
            '</urn:checkVat></soap:Body></soap:Envelope>'

    $sXML_data = StringReplace($sXML_data, '#$sStat', $sStat)
    $sXML_data = StringReplace($sXML_data, '#$sDic', $sDic)

    $sHeader = _
            'Content-Type' & @TAB & 'Text/xml' & @CRLF & _
            'SOAPAction' & @TAB & '""'

    $i = uf_sys_http_prikaz('POST', $sURL, '', '', $sHeader, $sXML_data, $aOutput) ; wrapper for WinHttp.WinHttpRequest.5.1
    If $i <> 0 Then
        Return 'Chyba při odesílání HTTP požadavku.' & @CRLF & 'číslo chyby: ' & String($i)
    EndIf

    If Not @Compiled Then _ArrayDisplay($aOutput)
    ; nf_msgupo($aOutput[$__g_iOutput_Status] + '~n' + $aOutput[$__g_iOutput_StatusText] + '~n~n' + $aOutput[$__g_iOutput_allresponseheaders]  + '~n~n' + $aOutput[$__g_iOutput_responsetext])

    ; pokud nedojde k chybe obsahuje $aOutput[$__g_iOutput_responsetext] XML data s vysledkem
    ; v pripade chyby obsahuje $aOutput[$__g_iOutput_responsetext] HTML popis chyby
    $sXML = $aOutput[$__g_iOutput_ResponseText]

    ; POZOR: XML obsahuje ceske znaky zakodovane pomoci HTML, napr: Anton&#xED;n
    ; $sXML = uf_sys_conv_html_1250($sXML)

    ; HTTP status OK je 200
    If $aOutput[$__g_iOutput_status] <> '200' Then
        $spom = _StringBetween($sXML, '<faultstring>', '</faultstring>')
        If $spom <> '' Then ; chyba ze SOAP serveru (v XML tvaru)
            Return 'Chyba v XML souboru.~npopis chyby: ' & $spom
        Else ; zrejme chyba HTTP (v HTML tvaru)
;~          Return 'Chyba při odesílání HTTP požadavku.~nstatus text: ' + $aOutput[$__g_iOutput_statustext] + '~nresponse text: ' + uf_sys_html2txt($aOutput[$__g_iOutput_responsetext])
            Return 'Chyba při odesílání HTTP požadavku.' & @CRLF & 'status text: ' & $aOutput[$__g_iOutput_statustext] & @CRLF & 'response text: ' & $aOutput[$__g_iOutput_responsetext]
        EndIf
    EndIf

    If StringLeft($sXML, 5) = '<?xml' Then
        MsgBox(0, '$sXML', $sXML)

        #cs
            $o_str_dic.stat = $sStat
            $o_str_dic.dic = $sDic
            $o_str_dic.name = _StringBetween($sXML, '<urn:name>', '</urn:name>')
            $o_str_dic.address = _StringBetween($sXML, '<urn:address>', '</urn:address>')
            $o_str_dic.valid = _StringBetween($sXML, '<urn:valid>', '</urn:valid>')

        #ce
    ElseIf StringLeft($sXML, 14) = '<soap:Envelope' Then
        MsgBox(0, '$sXML', $sXML)

        #cs
            $o_str_dic.stat = $sStat
            $o_str_dic.dic = $sDic
            $o_str_dic.name = _StringBetween($sXML, '<name>', '</name>')
            $o_str_dic.address = _StringBetween($sXML, '<address>', '</address>')
            $o_str_dic.valid = _StringBetween($sXML, '<valid>', '</valid>')

        #ce
    Else
        Return 'Chyba v XML souboru.' & @CRLF & 'nsoubor nemá správnou XML hlavičku' & @CRLF & @CRLF & $sXML ; v pripade chybne URL muze vratit HTML s chybou
    EndIf

    Return ''
EndFunc   ;==>uf_c_kontrola_dic

Func uf_sys_http_prikaz(Const $sCOMMAND, Const $sURL, Const $sUserName, Const $sPassword, $sHeader, Const $sXML_data, ByRef $aOutput)

    ; $sCOMMAND - GET/PUT/POST/...
    ; $sURL - https:;www.server.com:port/adresar
    ; $sHeader - seznam vsech udaju hlavicky ve tvaru: Title1~tValue1~nTitle2~tValue2~nTitle3~tValue3

    ; pri chybe vrati zaporny chybovy kod
    ; pri OK vrati 0

    Local $iHTTPREQUEST_PROXYSETTING_DEFAULT = 0
    Local $iHTTPREQUEST_PROXYSETTING_PRECONFIG = 0
    Local $iHTTPREQUEST_PROXYSETTING_DIRECT = 1
    Local $iHTTPREQUEST_PROXYSETTING_PROXY = 2
    Local $iHTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
    Local $iHTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1

    Local $sHeader_cast, $sTitle, $sValue
    Local $oHttpRequest = ObjCreate('WinHttp.WinHttpRequest.5.1')

    $oHttpRequest.Open($sCOMMAND, $sURL, False)
    If $sUserName <> '' Then $oHttpRequest.SetCredentials($sUserName, $sPassword, $iHTTPREQUEST_SETCREDENTIALS_FOR_SERVER) ; name, password

    If $sHeader <> '' Then ; header
        ; pozn: udaje hlavicky se musi nastavit po jednom

        ; While $sHeader <> ''
        $sHeader_cast = StringSplit($sHeader, '~n')[1] ; Title1~tValue1
        $sTitle = StringSplit($sHeader_cast, '~t')[1]
        $sValue = $sHeader_cast
        $oHttpRequest.SetRequestHeader($sTitle, $sValue)
        ;WEnd
    EndIf

    $oHttpRequest.Send($sXML_data)

    $aOutput[$__g_iOutput_Status] = String($oHttpRequest.Status)
    $aOutput[$__g_iOutput_Status] = $oHttpRequest.StatusText
    $aOutput[$__g_iOutput_AllResponseHeaders] = $oHttpRequest.GetAllResponseHeaders()
    $aOutput[$__g_iOutput_ResponseText] = $oHttpRequest.ResponseText

    $oHttpRequest = Null
    Return 0
EndFunc   ;==>uf_sys_http_prikaz

Func _ConsoleOut($string)
    ConsoleWrite(BinaryToString(StringToBinary($string, 4), 1) & @CRLF)
EndFunc   ;==>_ConsoleOut

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    _ConsoleOut(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

It works :cheer:

;~ http://ec.europa.eu/taxation_customs/vies/technicalInformation.html

#include <String.au3>
#include <array.au3>

Global Enum _
        $__g_iOutput_Status, _
        $__g_iOutput_StatusText, _
        $__g_iOutput_AllResponseHeaders, _
        $__g_iOutput_ResponseText, _
        $__g_iOutput_ENUMCOUNTER

Local $o_str_dic
; Checking: TeamViewer GmbH NIP
MsgBox(0, '', uf_c_kontrola_dic('DE245838579', $o_str_dic))
; Checking: Avangate BV
MsgBox(0, '', uf_c_kontrola_dic('NL815605468B01', $o_str_dic))

Func uf_c_kontrola_dic($sDic, ByRef $o_str_dic)
    ; pri chybe vrati chybove hlaseni
    ; pri OK vrati prazdny retezec a naplni strukturu

    Local $aOutput[$__g_iOutput_ENUMCOUNTER]
    Local $i
    Local $spom, $sXML, $sXML_data, $sHeader, $sStat, $sURL, $saction

    ; na vstupu bude DIC vcetne statu, ale zde se musi rozlozit na stat a samotne cislo dic
    $sStat = StringUpper(StringLeft($sDic, 2)) ; country
    $sDic = StringMid($sDic, 3) ; VAT

    $sURL = 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService;checkVat'

    $spom = StringSplit($sURL, ';')[1]
    $saction = $sURL ; nyni uz nevyuzity - not used now
    $sURL = $spom

;~  $sXML_data = '<?xml version="1.0" encoding="utf-8"?> ' & _


    #cs http://ec.europa.eu/taxation_customs/vies/technicalInformation.html
        ; <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>MS</urn:countryCode>
        ;          <urn:vatNumber>TESTVATNUMBER</urn:vatNumber>
        ;       </urn:checkVat>
        ;    </soapenv:Body>
        ; </soapenv:Envelope>
    #ce
    
    $sXML_data = _
            '<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>' & $sStat & '</urn:countryCode>' & _
            '         <urn:vatNumber>' & $sDic & '</urn:vatNumber>' & _
            '      </urn:checkVat>' & _
            '   </soapenv:Body>' & _
            '</soapenv:Envelope>' & _
            ''

    $sHeader = _
            'Content-Type' & @TAB & 'Text/xml' & @CRLF & _
            'SOAPAction' & @TAB & '""'

    $i = uf_sys_http_prikaz('POST', $sURL, '', '', $sHeader, $sXML_data, $aOutput) ; wrapper for WinHttp.WinHttpRequest.5.1
    If $i <> 0 Then
        Return 'Chyba při odesílání HTTP požadavku.' & @CRLF & 'číslo chyby: ' & String($i)
    EndIf

    If Not @Compiled Then _ArrayDisplay($aOutput)
    ; nf_msgupo($aOutput[$__g_iOutput_Status] + '~n' + $aOutput[$__g_iOutput_StatusText] + '~n~n' + $aOutput[$__g_iOutput_allresponseheaders]  + '~n~n' + $aOutput[$__g_iOutput_responsetext])

    ; pokud nedojde k chybe obsahuje $aOutput[$__g_iOutput_responsetext] XML data s vysledkem
    ; v pripade chyby obsahuje $aOutput[$__g_iOutput_responsetext] HTML popis chyby
    $sXML = $aOutput[$__g_iOutput_ResponseText]

    ; POZOR: XML obsahuje ceske znaky zakodovane pomoci HTML, napr: Antonín
    ; $sXML = uf_sys_conv_html_1250($sXML)

    ; HTTP status OK je 200
    If $aOutput[$__g_iOutput_status] <> '200' Then
        $spom = _StringBetween($sXML, '<faultstring>', '</faultstring>')
        If $spom <> '' Then ; chyba ze SOAP serveru (v XML tvaru)
            Return 'Chyba v XML souboru.~npopis chyby: ' & $spom
        Else ; zrejme chyba HTTP (v HTML tvaru)
;~          Return 'Chyba při odesílání HTTP požadavku.~nstatus text: ' + $aOutput[$__g_iOutput_statustext] + '~nresponse text: ' + uf_sys_html2txt($aOutput[$__g_iOutput_responsetext])
            Return 'Chyba při odesílání HTTP požadavku.' & @CRLF & 'status text: ' & $aOutput[$__g_iOutput_statustext] & @CRLF & 'response text: ' & $aOutput[$__g_iOutput_responsetext]
        EndIf
    EndIf

    If StringLeft($sXML, 5) = '<?xml' Then
        MsgBox(0, '$sXML', $sXML)

        #cs
            $o_str_dic.stat = $sStat
            $o_str_dic.dic = $sDic
            $o_str_dic.name = _StringBetween($sXML, '<urn:name>', '</urn:name>')
            $o_str_dic.address = _StringBetween($sXML, '<urn:address>', '</urn:address>')
            $o_str_dic.valid = _StringBetween($sXML, '<urn:valid>', '</urn:valid>')

        #ce
    ElseIf StringLeft($sXML, 14) = '<soap:Envelope' Then
        MsgBox(0, '$sXML', $sXML)

        #cs
            $o_str_dic.stat = $sStat
            $o_str_dic.dic = $sDic
            $o_str_dic.name = _StringBetween($sXML, '<name>', '</name>')
            $o_str_dic.address = _StringBetween($sXML, '<address>', '</address>')
            $o_str_dic.valid = _StringBetween($sXML, '<valid>', '</valid>')

        #ce
    Else
        Return 'Chyba v XML souboru.' & @CRLF & 'nsoubor nemá správnou XML hlavičku' & @CRLF & @CRLF & $sXML ; v pripade chybne URL muze vratit HTML s chybou
    EndIf

    Return ''
EndFunc   ;==>uf_c_kontrola_dic

Func uf_sys_http_prikaz(Const $sCOMMAND, Const $sURL, Const $sUserName, Const $sPassword, $sHeader, Const $sXML_data, ByRef $aOutput)

    If Not @Compiled Then ConsoleWrite($sXML_data & @CRLF)
    ; $sCOMMAND - GET/PUT/POST/...
    ; $sURL - https:;www.server.com:port/adresar
    ; $sHeader - seznam vsech udaju hlavicky ve tvaru: Title1~tValue1~nTitle2~tValue2~nTitle3~tValue3

    ; pri chybe vrati zaporny chybovy kod
    ; pri OK vrati 0

    Local $iHTTPREQUEST_PROXYSETTING_DEFAULT = 0
    Local $iHTTPREQUEST_PROXYSETTING_PRECONFIG = 0
    Local $iHTTPREQUEST_PROXYSETTING_DIRECT = 1
    Local $iHTTPREQUEST_PROXYSETTING_PROXY = 2
    Local $iHTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
    Local $iHTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1

    Local $sHeader_cast, $sTitle, $sValue

    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
    Local $oHttpRequest = ObjCreate('WinHttp.WinHttpRequest.5.1')

    $oHttpRequest.Open($sCOMMAND, $sURL, False)
    If $sUserName <> '' Then $oHttpRequest.SetCredentials($sUserName, $sPassword, $iHTTPREQUEST_SETCREDENTIALS_FOR_SERVER) ; name, password

    If $sHeader <> '' Then ; header
        ; pozn: udaje hlavicky se musi nastavit po jednom

        ; While $sHeader <> ''
        $sHeader_cast = StringSplit($sHeader, '~n')[1] ; Title1~tValue1
        $sTitle = StringSplit($sHeader_cast, '~t')[1]
        $sValue = $sHeader_cast
        $oHttpRequest.SetRequestHeader($sTitle, $sValue)
        ;WEnd
    EndIf

    $oHttpRequest.Send($sXML_data)

    $aOutput[$__g_iOutput_Status] = String($oHttpRequest.Status)
    $aOutput[$__g_iOutput_Status] = $oHttpRequest.StatusText
    $aOutput[$__g_iOutput_AllResponseHeaders] = $oHttpRequest.GetAllResponseHeaders()
    $aOutput[$__g_iOutput_ResponseText] = $oHttpRequest.ResponseText

    $oHttpRequest = Null
    Return 0
EndFunc   ;==>uf_sys_http_prikaz

Func _ConsoleOut($string)
    ConsoleWrite(BinaryToString(StringToBinary($string, 4), 1) & @CRLF)
EndFunc   ;==>_ConsoleOut

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    _ConsoleOut(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

 

Edited by mLipok
#CS >> #cs

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • 5 years later...
Posted
  On 7/16/2021 at 12:42 PM, maniootek said:

I tested your code

Expand  

Which one ? Mine recent version ?

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted
  On 10/6/2015 at 10:51 PM, mLipok said:

It works :cheer:

;~ http://ec.europa.eu/taxation_customs/vies/technicalInformation.html

#include <String.au3>
#include <array.au3>

Global Enum _
        $__g_iOutput_Status, _
        $__g_iOutput_StatusText, _
        $__g_iOutput_AllResponseHeaders, _
        $__g_iOutput_ResponseText, _
        $__g_iOutput_ENUMCOUNTER

Local $o_str_dic
; Checking: TeamViewer GmbH NIP
MsgBox(0, '', uf_c_kontrola_dic('DE245838579', $o_str_dic))
; Checking: Avangate BV
MsgBox(0, '', uf_c_kontrola_dic('NL815605468B01', $o_str_dic))

Func uf_c_kontrola_dic($sDic, ByRef $o_str_dic)
    ; pri chybe vrati chybove hlaseni
    ; pri OK vrati prazdny retezec a naplni strukturu

    Local $aOutput[$__g_iOutput_ENUMCOUNTER]
    Local $i
    Local $spom, $sXML, $sXML_data, $sHeader, $sStat, $sURL, $saction

    ; na vstupu bude DIC vcetne statu, ale zde se musi rozlozit na stat a samotne cislo dic
    $sStat = StringUpper(StringLeft($sDic, 2)) ; country
    $sDic = StringMid($sDic, 3) ; VAT

    $sURL = 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService;checkVat'

    $spom = StringSplit($sURL, ';')[1]
    $saction = $sURL ; nyni uz nevyuzity - not used now
    $sURL = $spom

;~  $sXML_data = '<?xml version="1.0" encoding="utf-8"?> ' & _


    #cs http://ec.europa.eu/taxation_customs/vies/technicalInformation.html
        ; <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>MS</urn:countryCode>
        ;          <urn:vatNumber>TESTVATNUMBER</urn:vatNumber>
        ;       </urn:checkVat>
        ;    </soapenv:Body>
        ; </soapenv:Envelope>
    #ce
    
    $sXML_data = _
            '<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>' & $sStat & '</urn:countryCode>' & _
            '         <urn:vatNumber>' & $sDic & '</urn:vatNumber>' & _
            '      </urn:checkVat>' & _
            '   </soapenv:Body>' & _
            '</soapenv:Envelope>' & _
            ''

    $sHeader = _
            'Content-Type' & @TAB & 'Text/xml' & @CRLF & _
            'SOAPAction' & @TAB & '""'

    $i = uf_sys_http_prikaz('POST', $sURL, '', '', $sHeader, $sXML_data, $aOutput) ; wrapper for WinHttp.WinHttpRequest.5.1
    If $i <> 0 Then
        Return 'Chyba při odesílání HTTP požadavku.' & @CRLF & 'číslo chyby: ' & String($i)
    EndIf

    If Not @Compiled Then _ArrayDisplay($aOutput)
    ; nf_msgupo($aOutput[$__g_iOutput_Status] + '~n' + $aOutput[$__g_iOutput_StatusText] + '~n~n' + $aOutput[$__g_iOutput_allresponseheaders]  + '~n~n' + $aOutput[$__g_iOutput_responsetext])

    ; pokud nedojde k chybe obsahuje $aOutput[$__g_iOutput_responsetext] XML data s vysledkem
    ; v pripade chyby obsahuje $aOutput[$__g_iOutput_responsetext] HTML popis chyby
    $sXML = $aOutput[$__g_iOutput_ResponseText]

    ; POZOR: XML obsahuje ceske znaky zakodovane pomoci HTML, napr: Antonín
    ; $sXML = uf_sys_conv_html_1250($sXML)

    ; HTTP status OK je 200
    If $aOutput[$__g_iOutput_status] <> '200' Then
        $spom = _StringBetween($sXML, '<faultstring>', '</faultstring>')
        If $spom <> '' Then ; chyba ze SOAP serveru (v XML tvaru)
            Return 'Chyba v XML souboru.~npopis chyby: ' & $spom
        Else ; zrejme chyba HTTP (v HTML tvaru)
;~          Return 'Chyba při odesílání HTTP požadavku.~nstatus text: ' + $aOutput[$__g_iOutput_statustext] + '~nresponse text: ' + uf_sys_html2txt($aOutput[$__g_iOutput_responsetext])
            Return 'Chyba při odesílání HTTP požadavku.' & @CRLF & 'status text: ' & $aOutput[$__g_iOutput_statustext] & @CRLF & 'response text: ' & $aOutput[$__g_iOutput_responsetext]
        EndIf
    EndIf

    If StringLeft($sXML, 5) = '<?xml' Then
        MsgBox(0, '$sXML', $sXML)

        #cs
            $o_str_dic.stat = $sStat
            $o_str_dic.dic = $sDic
            $o_str_dic.name = _StringBetween($sXML, '<urn:name>', '</urn:name>')
            $o_str_dic.address = _StringBetween($sXML, '<urn:address>', '</urn:address>')
            $o_str_dic.valid = _StringBetween($sXML, '<urn:valid>', '</urn:valid>')

        #ce
    ElseIf StringLeft($sXML, 14) = '<soap:Envelope' Then
        MsgBox(0, '$sXML', $sXML)

        #cs
            $o_str_dic.stat = $sStat
            $o_str_dic.dic = $sDic
            $o_str_dic.name = _StringBetween($sXML, '<name>', '</name>')
            $o_str_dic.address = _StringBetween($sXML, '<address>', '</address>')
            $o_str_dic.valid = _StringBetween($sXML, '<valid>', '</valid>')

        #ce
    Else
        Return 'Chyba v XML souboru.' & @CRLF & 'nsoubor nemá správnou XML hlavičku' & @CRLF & @CRLF & $sXML ; v pripade chybne URL muze vratit HTML s chybou
    EndIf

    Return ''
EndFunc   ;==>uf_c_kontrola_dic

Func uf_sys_http_prikaz(Const $sCOMMAND, Const $sURL, Const $sUserName, Const $sPassword, $sHeader, Const $sXML_data, ByRef $aOutput)

    If Not @Compiled Then ConsoleWrite($sXML_data & @CRLF)
    ; $sCOMMAND - GET/PUT/POST/...
    ; $sURL - https:;www.server.com:port/adresar
    ; $sHeader - seznam vsech udaju hlavicky ve tvaru: Title1~tValue1~nTitle2~tValue2~nTitle3~tValue3

    ; pri chybe vrati zaporny chybovy kod
    ; pri OK vrati 0

    Local $iHTTPREQUEST_PROXYSETTING_DEFAULT = 0
    Local $iHTTPREQUEST_PROXYSETTING_PRECONFIG = 0
    Local $iHTTPREQUEST_PROXYSETTING_DIRECT = 1
    Local $iHTTPREQUEST_PROXYSETTING_PROXY = 2
    Local $iHTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
    Local $iHTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1

    Local $sHeader_cast, $sTitle, $sValue

    Local $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
    Local $oHttpRequest = ObjCreate('WinHttp.WinHttpRequest.5.1')

    $oHttpRequest.Open($sCOMMAND, $sURL, False)
    If $sUserName <> '' Then $oHttpRequest.SetCredentials($sUserName, $sPassword, $iHTTPREQUEST_SETCREDENTIALS_FOR_SERVER) ; name, password

    If $sHeader <> '' Then ; header
        ; pozn: udaje hlavicky se musi nastavit po jednom

        ; While $sHeader <> ''
        $sHeader_cast = StringSplit($sHeader, '~n')[1] ; Title1~tValue1
        $sTitle = StringSplit($sHeader_cast, '~t')[1]
        $sValue = $sHeader_cast
        $oHttpRequest.SetRequestHeader($sTitle, $sValue)
        ;WEnd
    EndIf

    $oHttpRequest.Send($sXML_data)

    $aOutput[$__g_iOutput_Status] = String($oHttpRequest.Status)
    $aOutput[$__g_iOutput_Status] = $oHttpRequest.StatusText
    $aOutput[$__g_iOutput_AllResponseHeaders] = $oHttpRequest.GetAllResponseHeaders()
    $aOutput[$__g_iOutput_ResponseText] = $oHttpRequest.ResponseText

    $oHttpRequest = Null
    Return 0
EndFunc   ;==>uf_sys_http_prikaz

Func _ConsoleOut($string)
    ConsoleWrite(BinaryToString(StringToBinary($string, 4), 1) & @CRLF)
EndFunc   ;==>_ConsoleOut

; User's COM error function. Will be called if COM error occurs
Func _ErrFunc($oError)
    ; Do anything here.
    _ConsoleOut(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
            @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
            @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
            @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
            @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
            @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
            @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
            @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
            @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
            @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc   ;==>_ErrFunc

 

Expand  

I tried this

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...