Click here to Skip to main content
15,887,214 members
Articles / Desktop Programming / Windows Forms
Tip/Trick

Checking the EU VAT Number with an German VAT for non German VAT

Rate me:
Please Sign up or sign in to vote.
4.60/5 (3 votes)
1 Dec 2014CPOL 20.8K   224   3   5
Easy library for checking VAT Numbers of European Companies. Only usable with an German VAT for non German VAT!!!

Introduction

This library and demo project are only usable for German users with a German VAT!!!

The "Bundeszentralamt für Steuern" has made an interface to check VAT Numbers from other countries. More information can be found here.

The Code

The main method is just a call of the XML RPC API over an HTML link:

C#
       [XmlRpcUrl("https://evatr.bff-online.de/")]
       public interface ISumAndDiff : IXmlRpcProxy
       {
           [XmlRpcMethod("evatrRPC")]
           string testMyClient(string UstId_1, string UstId_2,
           string Firmenname, string Ort, string PLZ, string Strasse, string Druck);
       }

public int Response(string UstId_1, string UstId_2,
           string Firmenname, string Ort, string PLZ, string Strasse, bool Druck)
       {
           _Message = string.Empty;
           _Erg_Name = string.Empty;
           _Erg_Ort = string.Empty;
           _Erg_PLZ = string.Empty;
           _Erg_Str = string.Empty;
           _Druck = string.Empty;

           int errorCode = 0;

           ISumAndDiff proxy = XmlRpcProxyGen.Create<ISumAndDiff>();

           string ret = proxy.testMyClient(UstId_1, UstId_2, Firmenname,
           Ort, PLZ, Strasse, Druck ? "ja" : "nein");

           var xmlDoc = new XmlDocument();
           xmlDoc.LoadXml(ret);

           XmlNodeList elemList = xmlDoc.GetElementsByTagName("string");

           int.TryParse(elemList[3].InnerXml.ToString(), out errorCode);

           DateTime.TryParse(elemList[23].InnerXml.ToString(), out GueltigAb);
           DateTime.TryParse(elemList[25].InnerXml.ToString(), out GueltigBis);

           _Erg_Name =elemList[21].InnerText;
           _Erg_Ort = elemList[17].InnerText;
           _Erg_PLZ = elemList[9].InnerText;
           _Erg_Str = elemList[31].InnerText;
           _Druck = elemList[7].InnerText;

           if (ErrorCodes.Keys.Contains(errorCode))
           {
               _Message = String.Format(ErrorCodes[errorCode],
               GueltigAb.ToShortDateString(), GueltigBis.ToShortDateString());
           }
           else
           {
               _Message = string.Empty;
           }

           return errorCode;
       }

Using the Code

To use the code, the DLL has to be added to the project.

The only thing needed to check a UID Number is to call the "Code" method. It gives as result the ErrorCode of the API (the code 200 means that the UID is OK) and a message that explains the ErrorCode.

C#
int code = 0;

                UID.Check check = new Check();

                code = check.Response
                (UstId_1, UstId_2, Firmenname, Ort, PLZ, Strasse, chkQualified.Checked);

                lblErg_Fname.Text =check.ParameterMessage(check.Erg_Name);
                lblErg_Ort.Text = check.ParameterMessage(check.Erg_Ort);
                lblErg_PLZ.Text = check.ParameterMessage(check.Erg_PLZ);
                lblErg_Str.Text = check.ParameterMessage(check.Erg_Str);

txtResult.Text = check.Message;

You can find all ErrorCodes here. (01.12.2014)

History

  • 04.12.2014 - Detailed Parameter Results Added
  • 12.12.2014 - Using the "CookComputing.XmlRpc" Library, the Response recognizes all Company Names

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer ICS Logistik & Transport GmbH
Germany Germany
Born in Bosnia and Herzegowina where I studied Traffic and Communication in the University of Sarajevo. After the Bachelor, found a Job in a Logistic Company in Germany where I live and work now as an Software developer for our Company needs.

With programming I started as an hoby at work. For now I have almost 2 years programing experience. First with excel then VBA in Excel. That growed up to VBA with Access and a first Access DB. Then an SQL Server camed in and VBA with Access could not handle it. The next move was of cource VB.Net but with Visual Studio I came in contact with C#.

Comments and Discussions

 
SuggestionUse VIES VAT Validation web service Pin
The Real Paps2-Dec-14 3:24
professionalThe Real Paps2-Dec-14 3:24 
GeneralRe: Use VIES VAT Validation web service Pin
TarikHuber3-Dec-14 1:19
professionalTarikHuber3-Dec-14 1:19 
GeneralMy vote of 4 Pin
fredatcodeproject1-Dec-14 3:43
professionalfredatcodeproject1-Dec-14 3:43 
GeneralRe: My vote of 4 Pin
TarikHuber1-Dec-14 3:48
professionalTarikHuber1-Dec-14 3:48 
GeneralRe: My vote of 4 Pin
fredatcodeproject1-Dec-14 3:50
professionalfredatcodeproject1-Dec-14 3:50 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.