In relation to tracker.openpetra.org/view.php?id=2680:
I have now this code, that is quite useful in the german office:
private static bool ConvertBankAccountCodeToIBANandBic(string AAccountNumber, string ABankSortCode, out string AIBAN, out string ABIC)
{
string url =
TAppSettingsManager.GetValue("SEPA.ConvertBankAccountNumbersToIBAN.URL", "https://kontocheck.solidcharity.com/index.php", false) +
"?kto=" + AAccountNumber + "&blz=" + ABankSortCode;
string result = THTTPUtils.ReadWebsite(url);
if (result == null)
{
throw new Exception("ConvertBankAccountCodeToIBANandBic: problem reading IBAN and BIC from " + url);
}
XmlDocument doc = new XmlDocument();
doc.LoadXml(result);
if (TXMLParser.FindNodeRecursive(doc.DocumentElement, "kontocheck").InnerText != "ok")
{
TLogging.Log("Problem with converting bank account number to IBAN " + AAccountNumber + " " + ABankSortCode);
TLogging.Log(result);
ABIC = string.Empty;
AIBAN = string.Empty;
return false;
}
AIBAN = TXMLParser.FindNodeRecursive(doc.DocumentElement, "iban").InnerText;
ABIC = TXMLParser.FindNodeRecursive(doc.DocumentElement, "bic").InnerText;
return true;
}
private static bool ValidateIBANandBic(string AIban, ref string ABic)
{
string url =
TAppSettingsManager.GetValue("SEPA.ConvertBankAccountNumbersToIBAN.URL", "https://kontocheck.solidcharity.com/index.php", false) +
"?iban=" + AIban + "&bic=" + ABic;
string result = THTTPUtils.ReadWebsite(url);
if (result == null)
{
throw new Exception("ValidateIBANandBic: problem validating IBAN and BIC from " + url);
}
XmlDocument doc = new XmlDocument();
doc.LoadXml(result);
if (TXMLParser.FindNodeRecursive(doc.DocumentElement, "iban").InnerText != "1")
{
return false;
}
if (TXMLParser.FindNodeRecursive(doc.DocumentElement, "bic").InnerText != "1")
{
// use the proposed BIC
ABic = TXMLParser.FindNodeRecursive(doc.DocumentElement, "bic").InnerText;
// return false;
}
return true;
}
This makes use of the GPL software konto_check, which I have installed on my server. For installing it anywhere else, see kontocheck.solidcharity.com/
I guess there are too many rules for validating IBAN numbers, so it is better to use a library that was specifically written for this purpose.
I tried to compile it to a dll, but was not sure if that works on Mono too.
So the web service was the easiest solution.