Using Sortcode and Bank Account Validation Service in Visual Studio - ASP and C# Example

This demonstration can be seen functioning at Bankcheck Demonstration

  • BankCheck has been developed in Dot Net for easy interfacing for Visual Basic and Visual C# developers. To make use of the service add a Web Reference to your project. The following examples are all in C# however the same applies to VB.

  • Once you have created your project, in the solution explorer select “Add Web Reference”. This will present you with the following dialog box to enter the url. Once the url has been entered the BankCheck interface will be displayed. http://www.mosaicsoftware.co.uk/services/bankcheck/bankcheck.asmx

    bank account validation add web reference

  • As BankCheck is provided solely as a web-based service, the Industry Sortcode Directory (ISCD) is updated automatically when we receive a new copy from Bacs. Older methods to download the ISCD have been made obsolete.

  • Create a simple form with an asp:TextBox for the sortcode and for the account. In our examples we have named the TextBoxes sortcode and account respectively. We have also placed a multiline textbox on the form in which to display the results.

  • To instantiate the service and instantiate the header the following code can be used. Contact Mosaic Software for a test BankCheck UserID and Password

                                    
    bankCheck = new BankcheckService.BankCheck(); 
    bankCheck.BankcheckHeaderValue = new BankcheckService.BankcheckHeader();
    bankCheck.BankcheckHeaderValue.UserId = "youruserid";
    bankCheck.BankcheckHeaderValue.Password = "yourpassword";
                   
                                    
                                    
  • We then need to create a method to handle the sortcode TextChanged event. Thes method calls GetBank of the service. If the Bank object returned is a null then the sortcode is not valid. Otherwise the Bank object can be used to get populate the resuts field.

                                    
    protected void sortcode_TextChanged(object sender, EventArgs e)
    {
        BankcheckService.Bank bank = bankCheck.GetBank(sortcode.Text);
        if (bank != null)
        {
            bankDetails.Text = string.Format(@"{0}\n{1}\n{2}\n{3}\n{4}\n{5}\n", bank.ShortNameOfOwningBank, bank.ShortBranchTitle, bank.Address1, bank.Address2, bank.City, bank.Postcode);
            messageLabel.Text = "The sortcode exists in the ISCD";
            if (bank.PermitDebits)
                ddAllowed.Text = "Direct Debits Allowed";
            else
                ddAllowed.Text = "Direct Debits NOT Allowed";
    
            if (bank.PermitCredits)
                dcAllowed.Text = "Direct Credits Allowed";
            else
                dcAllowed.Text = "Direct Credits NOT Allowed";
        }
        else
        {
            messageLabel.Text = "The sortcode does not exist in the ISCD";
        }
    }
                                    
                                    
  • We also need to create a method to handle the accountNumber TextChanged event. Thes method calls ModulusCheck of the service and returns a true or false on a pass or fail respectively.

                                    
    protected void accountNumber_TextChanged(object sender, EventArgs e)
    {
        if (bankCheck.ModulusCheck(sortcode.Text, accountNumber.Text))
        {
            messageLabel.Text = "The sortcode and account PASSED modulus check";
        }
        else
        {
            messageLabel.Text = "The sortcode and account FAILED modulus check";
        }
    }
                                    
                                    
This demonstration can be seen functioning at Bankcheck Demonstration