Home
> Uncategorized > Using the official #VIES API in c# for #VAT lookups
Using the official #VIES API in c# for #VAT lookups
Sometimes it surprises me how some companies repackage a free, official API, and then charge for it, VATAPI.com is a good example of this, the official VIES EU VAT commission offers a free webservice available here:
http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl
And you can use it from C# with some code as follows,
var vat = new vat.checkVatPortTypeClient();
bool blnValid;
string strName;
string strAddress;
vat.checkVat(ref strCountryCode, ref strVatNumber, out blnValid, out strName, out strAddress);
That’s what’s behind my VAT checker app for iOS:
https://itunes.apple.com/pl/app/vat/id524680827?mt=8
Categories: Uncategorized
Hi, nice post!
I copied your code, but I get an error invalid_input on the checkvat() method. Am I missing some configuration?
LikeLike
Hello,
Here is the code for vatCheck in c#
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 static EuropeanVatInformation Get(string countryCode, string vatNumber)
{
if (countryCode == null)
throw new ArgumentNullException(nameof(countryCode));
if (vatNumber == null)
throw new ArgumentNullException(nameof(vatNumber));
string _countryCode = countryCode;
string _vatNumber = vatNumber;
string _address = “”;
string _name = “”;
bool _valid = false;
ServiceReference2.checkVatPortTypeClient client = new ServiceReference2.checkVatPortTypeClient();
string ReqDate = client.checkVat(ref _countryCode, ref _vatNumber, out _valid, out _name, out _address);
if (_valid)
{
var info = new EuropeanVatInformation();
info.CountryCode = _countryCode;
info.VatNumber = _vatNumber;
info.Name = _name;
info.Address = _address;
return info;
}
return null;
}
}
LikeLike