EU created a service to obtain confirmation of the validity of the VAT identification number of any specified person. This service works with SOAP and can validate all the EU VAT. You just need to send the state code and the VAT.

This service works within the VIES environment (VAT Information Exchange System)

With this code, you can send a SOAP request to the VAT service. The XML is correclty formatted, you just need to use the paramertes you need. I found this very useful class:

public class EuropeanVatInformation
{
    private EuropeanVatInformation() { }

    public string CountryCode { get; private set; }
    public string VatNumber { get; private set; }
    public string Address { get; private set; }
    public string Name { get; private set; }
    public override string ToString() => CountryCode + " " + VatNumber + ": " + Name + ", " + Address.Replace("\n", ", ");

    public static EuropeanVatInformation Get(string countryCodeAndVatNumber)
    {
        if (countryCodeAndVatNumber == null)
            throw new ArgumentNullException(nameof(countryCodeAndVatNumber));

        if (countryCodeAndVatNumber.Length < 3)
            return null;

        return Get(countryCodeAndVatNumber.Substring(0, 2), countryCodeAndVatNumber.Substring(2));
    }

    public static EuropeanVatInformation Get(string countryCode, string vatNumber)
    {
        if (countryCode == null)
            throw new ArgumentNullException(nameof(countryCode));

        if (vatNumber == null)
            throw new ArgumentNullException(nameof(vatNumber));

        countryCode = countryCode.Trim();
        vatNumber = vatNumber.Trim().Replace(" ", string.Empty);

        const string url = "http://ec.europa.eu/taxation_customs/vies/services/checkVatService";
        const string xml = @&quot;<s><s>{0}{1}</s></s>";

        try
        {
            using (var client = new WebClient())
            {
                var doc = new XmlDocument();
                doc.LoadXml(client.UploadString(url, string.Format(xml, countryCode, vatNumber)));
                var response = doc.SelectSingleNode("//*[local-name()='checkVatResponse']") as XmlElement;
                if (response == null || response["valid"]?.InnerText != "true")
                    return null;

                var info = new EuropeanVatInformation();
                info.CountryCode = response["countryCode"].InnerText;
                info.VatNumber = response["vatNumber"].InnerText;
                info.Name = response["name"]?.InnerText;
                info.Address = response["address"]?.InnerText;
                return info;
            }
        }
        catch
        {
            return null;
        }
    }
}

To use it, just call it in this way:

EuropeanVatInformation.Get("IT00488410010");

The XML manage part isn’t the best one, but it’s ok for what I need here.

Below, a response sample done with SOAP UI:

screen-shot-2012-05-13-at-17-13-42

NOTE: In the past, I got this error (yes, they return the HTML code):


 Web Filter
 
 
<blockquote>
<TABLE border="0" cellPadding="1" width="100%">
<TR>
<TD>
 <big><strong></strong></big>
<big><strong></strong></big>
<FONT face="Helvetica" SIZE="3">
 <big>Access Denied </big>

 Your request has been denied for security reason.

<FONT face="Helvetica" SIZE="2">
 If you believe that this request should not be blocked, please contact <a href="mailto:snet@ec.europa.eu?subject=&#91;Blocked URL&#93; x.x.x.x / /checkVatService.wsdl">EC DIGIT SNet</a>.
If your request is urgent, please contact also the service helpdesk (+32)2 29 58181.
 </FONT>
 </TD>
</TR>
</TABLE></blockquote>
</FONT>
 

The problem was I sent too many wrong requests before to understand the correct way to do it. So, if this happened to you too, just follow the instructions and write an emial (and wait) or make a call.

WARNING: the email address in the error message is old. I called the number and they explained me this is an error and the correct email address to use is: EC-CENTRAL-HELPDESK@ec.europa.eu

 

Advertisements