public async Task <checkVatApproxResponse> CheckVatApproxAsync(string country, string vat, string countryReq, string vatReq) { checkVatApproxRequest approxRequest = new checkVatApproxRequest() { Body = new checkVatApproxRequestBody() { countryCode = country, vatNumber = vat, requesterCountryCode = countryReq, requesterVatNumber = vatReq, traderCity = "", traderCompanyType = "", traderName = "", traderPostcode = "", traderStreet = "" } }; checkVatApproxResponse approxResponse = new checkVatApproxResponse(); using (ServiceReference1.checkVatPortTypeClient client = new checkVatPortTypeClient()) { approxResponse = await client.checkVatApproxAsync(approxRequest.Body.countryCode, approxRequest.Body.vatNumber, approxRequest.Body.traderName, approxRequest.Body.traderCompanyType, approxRequest.Body.traderStreet, approxRequest.Body.traderPostcode, approxRequest.Body.traderCity, approxRequest.Body.requesterCountryCode, approxRequest.Body.requesterVatNumber); return(approxResponse); } }
public CheckVatApprox CheckVatApprox(string countryCode, string vatNumber, string requesterCountryCode = null, string requesterVatNumber = null) { try { var checkVatApproxRequest = new checkVatApproxRequest { countryCode = countryCode, vatNumber = vatNumber, requesterCountryCode = countryCode, requesterVatNumber = vatNumber }; var checkVatPortTypeClient = new checkVatPortTypeClient(); checkVatApproxResponse checkVatApproxResponse = checkVatPortTypeClient.checkVatApprox(checkVatApproxRequest); if (null != checkVatApproxResponse) { var xmlSerializer = new XmlSerializer(checkVatApproxResponse.GetType()); var textWriter = new StringWriter(); xmlSerializer.Serialize(textWriter, checkVatApproxResponse); CheckVatApprox checkVatApprox = XmlHelper.DeserializeXmlFromString <CheckVatApprox>(textWriter.ToString()); //#if DEBUG // _log4Net.Debug(JsonConvert.SerializeObject(checkVatApprox)); // _log4Net.Debug(JsonConvert.SerializeObject(checkVatApproxResponse)); //#endif return(checkVatApprox); } } catch (Exception e) { _log4Net.Error(e.Message, e); if (null != e.InnerException) { _log4Net.Error(e.InnerException.Message, e.InnerException); } } return(null); }
private async void VACheckAsync() { Task <checkVatApproxResponse> vatApproxTask = _vatService.CheckVatApproxAsync( cbVACountry.SelectedValue.ToString(), txtVANumber.Text, cbVACountryRequester.SelectedValue.ToString(), txtVANumberRequester.Text); checkVatApproxResponse vatApprox = new checkVatApproxResponse(); try { vatApprox = await vatApproxTask; if (vatApprox.Body.valid) { txtVAValid.Text = vatApprox.Body.valid.ToString(); txtVAName.Text = vatApprox.Body.traderName; txtVAAdress.Text = vatApprox.Body.traderAddress; txtVAId.Text = vatApprox.Body.requestIdentifier; txtVAVat.Text = vatApprox.Body.vatNumber; txtVADate.Text = vatApprox.Body.requestDate; txtVACountry.Text = vatApprox.Body.countryCode; btnVAXml.Enabled = true; } else { MessageBox.Show("STATUS: NIEAKTYWNY", "Walidacja numeru Vat", MessageBoxButtons.OK, MessageBoxIcon.Hand); } } catch (Exception ex) { if (ex.Message == "INVALID_REQUESTER_INFO") { MessageBox.Show("Niepoprawna wartość numeru vat pytającego dla wybranego kraju", "Błędny vat", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (ex.Message == "Empty Requester VAT number") { MessageBox.Show("Wartość numeru vat pytającego nie może być pusta", "Błędny vat", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else if (ex.Message == "GLOBAL_MAX_CONCURRENT_REQ") { MessageBox.Show("Maksymalna ilość konkurencyjnych zapytań została przekroczona. Spróbuj ponownie później", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (ex.Message == "MS_MAX_CONCURRENT_REQ") { MessageBox.Show("Maksymalna ilość konkurencyjnych zapytań została przekroczona. Spróbuj ponownie później", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (ex.Message == "SERVICE_UNAVAILABLE") { MessageBox.Show("Wystąpił błąd sieci lub serwera VIES. Spróbuj ponownie później", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (ex.Message == "MS_UNAVAILABLE") { MessageBox.Show("Wystąpił błąd sieci lub serwera VIES. Spróbuj ponownie później", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (ex.Message == "TIMEOUT") { MessageBox.Show("Oczekiwana odpowiedź nie została uzyskana w określonych ramach czasowych. Spróbuj ponownie później", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("Wystąpił nieoczekiwany błąd aplikacji", "Błąd", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }