0

http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl to check VAT in Italy. I wrote this

Public Function check_piva() As Date
    Dim pivawe As New checkvatService.europa.ec.checkVatService
    Dim piva As String = "0798012121lk9"
    Dim bb As Boolean
    Dim s As String
    Dim n As String = String.Empty
    Dim data As Date
    data = pivawe.checkVat("IT", piva, bb, n, n)
    MsgBox(data)
    Return data

It always return todays data if vat is either wrong or correct , I don-t either understand why a checkVAt function gives back a date not a string or boolean

I saw they also have checkVatAsync

Dim pivawe As New checkvatService.europa.ec.checkVatService
Dim piva As String = "0798012121lk9"
Dim bb As Boolean
Dim s As String
Dim n As String = String.Empty
Dim data As Date
pivawe.checkVatAsync("IT", piva)
MsgBox(data)
Return data     

This runs no error but I don-t get a value back. If I write

s = pivawe.checkVatAsync("IT", piva)

I get error

expression does not produce value.

May be web service simply does not work. Any suggestion thx

MatSnow
  • 7,357
  • 3
  • 19
  • 31
lucullo08
  • 41
  • 1
  • 10

1 Answers1

0

I don't quite understand what you are trying to archive but let's say if you need to validate a VAT number. Then you only need to consume it. In the below example I am passing the COUNTRY and VAT number immediately in the soap request but you can easily do string concatenation and pass dynamic variables there.

Imports System.Net

Module Module1

    Sub Main()

        Dim client As WebClient = New WebClient()
        client.Encoding = System.Text.Encoding.UTF8

        Dim request As String = "<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>IT</urn:countryCode>
                 <urn:vatNumber>XXXXXXXXXXX</urn:vatNumber>
              </urn:checkVat>
            </soapenv:Body>
            </soapenv:Envelope>"

        Dim response As String = ""

        Try
            response = client.UploadString("http://ec.europa.eu/taxation_customs/vies/services/checkVatService", request)
        Catch
            Console.WriteLine("Exception")
            'service throws WebException e.g. when non-EU VAT Is supplied
        End Try

        Console.WriteLine(response)
        Console.WriteLine("")

        If response.Contains("<valid>true</valid>") Then
            Console.WriteLine("VALID")
        Else
            Console.WriteLine("NOT")
        End If

        Console.ReadLine()

    End Sub

End Module

This will consume the SOAP and reply whether the VAT is valid in that country or not. XXXXXXXXXXX = Vat Number ;) Also you can turn them into variables as this excellent answer here by Borek has!

oetoni
  • 3,269
  • 5
  • 20
  • 35