Discovered by WCF and, therefore, began to study it. This is a C # console application. The code works fine except when I try to delete. If I enter an amount of the wrong type, it detects (catches), informs me of the incorrect input and sends it back to the menu prompt. This is wonderful and dandy, until I get to the part where I try to remove more dosha than mine (balance). Presumably, I should have reported that I did not have enough funds to leave so much. Instead, I get the following:
An unhandled exception of type "System.FormatException" occurred in mscorlib.dll
Where am I wrong?
the main
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ServiceModel; namespace BankAccountClient { class Program { static void Main(string[] args) { BankAccountClient.ServiceReference1.ServiceClient client = new ServiceReference1.ServiceClient(); bool done = false; do { Console.WriteLine("Select one of the following:"); Console.WriteLine("\t1 -- Withdraw"); Console.WriteLine("\t2 -- Deposit"); Console.WriteLine("\t3 -- Balance"); Console.Write("Enter Your selection (0 to exit): "); string strSelection = Console.ReadLine(); int iSel; try { iSel = int.Parse(strSelection); } catch (FormatException) { Console.WriteLine("\r\nWhat?\r\n"); continue; } Console.WriteLine("\nYou selected " + iSel + "\n"); switch (iSel) { case 0: done = true; break; case 1: int balance = client.Balance(); int amount;
WCF Service (Short)
public class Service : IService { private static int balance; public void Withdraw(int value) { balance -= value; } public void Deposit(int value) { balance += value; } public int Balance() { return balance; } }
source share