Exemple #1
0
        public async Task <IViesResult> CheckVatAsync(string countryCode, string vatNumber)
        {
            if (string.IsNullOrEmpty(countryCode))
            {
                var err = new Exception("country code should not be null or empty");
                return(new ViesResult(err));
            }
            if (string.IsNullOrEmpty(vatNumber))
            {
                var err = new Exception("vat number should not be null or empty");
                return(new ViesResult(err));
            }
            vatNumber = vatNumber
                        .Replace(" ", "")
                        .Replace(".", "")
                        .Replace("-", "");

            var request = new checkVatRequest(countryCode, vatNumber);

            try
            {
                var vs = new checkVatPortTypeClient();
                var vr = await vs.checkVatAsync(request);

                var vd = new ViesData(vr);
                return(new ViesResult(vd));
            }
            catch (Exception e)
            {
                return(new ViesResult(e));
            }
        }
Exemple #2
0
        public static async Task <bool> CheckVAT()
        {
            var countryCode = "PL";
            var vatNumber   = "8512389324";

            try
            {
                checkVatPortType client          = new checkVatPortTypeClient(checkVatPortTypeClient.EndpointConfiguration.checkVatPort, "http://ec.europa.eu/taxation_customs/vies/services/checkVatService");
                checkVatRequest  checkVatRequest = new checkVatRequest {
                    countryCode = countryCode, vatNumber = vatNumber
                };

                var sw = Stopwatch.StartNew();
                checkVatResponse response = await client.checkVatAsync(checkVatRequest);

                sw.Stop();
                Console.WriteLine("Time elapsed: {0}", sw.Elapsed);

                Console.WriteLine(response.valid);
                Console.WriteLine(response.name);
                Console.WriteLine(response.address);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
            return(true);
        }
Exemple #3
0
        public CheckVat CheckVat(string countryCode, string vatNumber)
        {
            try
            {
                var checkVatRequest = new checkVatRequest {
                    countryCode = countryCode, vatNumber = vatNumber
                };
                var checkVatPortTypeClient        = new checkVatPortTypeClient();
                checkVatResponse checkVatResponse = checkVatPortTypeClient.checkVat(checkVatRequest);
                if (null != checkVatResponse)
                {
                    var xmlSerializer = new XmlSerializer(checkVatResponse.GetType());
                    var textWriter    = new StringWriter();
                    xmlSerializer.Serialize(textWriter, checkVatResponse);
                    CheckVat checkVat = XmlHelper.DeserializeXmlFromString <CheckVat>(textWriter.ToString());
                    return(checkVat);
                }
            }
            catch (Exception e)
            {
                _log4Net.Error(e.Message, e);
                if (null != e.InnerException)
                {
                    _log4Net.Error(e.InnerException.Message, e.InnerException);
                }
            }

            return(null);
        }
Exemple #4
0
        /// <summary>
        /// Update a CompanyModel instance using the data from the webservice. This updates the "Vies" fields, the "valid" field
        /// and the LastWebServiceCall field.
        /// </summary>
        /// <param name="company">A CompanyModel instance that should be updated.</param>
        /// <returns></returns>
        public async Task <CompanyModel> UpdateCompanyAsync(CompanyModel company)
        {
            var request  = new checkVatRequest(company.VatIdentNo.Substring(0, 2), company.VatIdentNo.Substring(2));
            var response = await _client.checkVatAsync(request);

            company.ViesName           = response.name;
            company.ViesAddress        = response.address;
            company.Valid              = response.valid;
            company.LastWebServiceCall = response.requestDate;
            return(company);
        }
Exemple #5
0
        public async Task <checkVatResponse> CheckVatAsync(string country, string vat)
        {
            checkVatRequest vatRequest = new checkVatRequest()
            {
                Body = new checkVatRequestBody()
                {
                    countryCode = country,
                    vatNumber   = vat
                }
            };

            checkVatResponse vatResponse = new checkVatResponse();

            using (ServiceReference1.checkVatPortTypeClient client = new checkVatPortTypeClient())
            {
                vatResponse = await client.checkVatAsync(vatRequest.Body.countryCode, vatRequest.Body.vatNumber);

                return(vatResponse);
            }
        }