private async void button1_Click(object sender, EventArgs e) { UtilidadesClient cliente = new UtilidadesClient("http://localhost:2038/"); GetUtilidadesValidarIBANQuery param = new GetUtilidadesValidarIBANQuery(); param.RestKey = soapkey; param.DNI = textBox1.Text; var response = await cliente.UtilidadesValidarIBAN.Get(param); var stream = await response.RawContent.ReadAsStreamAsync(); using (var contentStream = await response.RawContent.ReadAsStreamAsync()) { contentStream.Seek(0, SeekOrigin.Begin); using (var sr = new StreamReader(contentStream)) { MultipleUtilidadesValidarIBANGet result = JsonConvert.DeserializeObject <MultipleUtilidadesValidarIBANGet>(sr.ReadToEnd()); bool valido = result.Ipbool.Value; if (valido) { MessageBox.Show("IBAN válido."); } else { MessageBox.Show("IBAN inválido."); } if (!valido && result.Error.Mensaje != null) { MessageBox.Show("Error: \n Codigo: " + result.Error.Codigo + "\n Mensaje: " + result.Error.Mensaje); } } } }
/// <summary> /// Valida el IBAN de un usuario - /Utilidades/validarIBAN /// </summary> /// <param name="iban"></param> /// <param name="restkey"></param> /// <returns>MultipleUtilidadesValidarIBANGet</returns> public IHttpActionResult GetValidarIBAN([FromUri] string bankAccount, [FromUri] string restkey) { // TODO: implement GetValidarIBAN - route: Utilidades/validarIBAN // var result = new MultipleUtilidadesValidarIBANGet(); // return Ok(result); MultipleUtilidadesValidarIBANGet salida = new MultipleUtilidadesValidarIBANGet() { Error = new Error() }; db = new db(); if (!db.ComprobarApiKey(restkey)) { salida.Error.Mensaje = "RestKey no coincide."; salida.Error.Codigo = 401; return(Ok(salida)); } salida.Ipbool = false; bankAccount = bankAccount.ToUpper(); //IN ORDER TO COPE WITH THE REGEX BELOW if (String.IsNullOrEmpty(bankAccount)) { return(Ok(salida)); } else if (System.Text.RegularExpressions.Regex.IsMatch(bankAccount, "^[A-Z0-9]")) { bankAccount = bankAccount.Replace(" ", String.Empty); string bank = bankAccount.Substring(4, bankAccount.Length - 4) + bankAccount.Substring(0, 4); int asciiShift = 55; StringBuilder sb = new StringBuilder(); foreach (char c in bank) { int v; if (Char.IsLetter(c)) { v = c - asciiShift; } else { v = int.Parse(c.ToString()); } sb.Append(v); } string checkSumString = sb.ToString(); int checksum = int.Parse(checkSumString.Substring(0, 1)); for (int i = 1; i < checkSumString.Length; i++) { int v = int.Parse(checkSumString.Substring(i, 1)); checksum *= 10; checksum += v; checksum %= 97; } salida.Ipbool = checksum == 1; return(Ok(salida)); } else { salida.Ipbool = false; return(Ok(salida)); } }