public double Buy(Currencies currency, double amount) { try { if (!UseAsmx) { // Call the WCF service currencyProx = currencyChf.CreateChannel(); return currencyProx.Buy(currency, amount); } else { // Call the WCF service currencyAsmxProx = currencyAsmxChf.CreateChannel(); return currencyAsmxProx.Buy(currency, amount); } } catch (Exception ex) { LoggingManager.Logger.Log(LoggingCategory.Error, StringsResource.FailedToContactCurrencyExchange + " " + ex.Message); throw new FaultException<CurrencyExchangeException> (new CurrencyExchangeException(StringsResource.FailedToContactCurrencyExchange + " " + ex.Message, ex)); } finally { var channel = currencyProx as ICommunicationObject; if ((channel != null) && (channel.State == CommunicationState.Opened)) channel.Close(); channel = currencyAsmxProx as ICommunicationObject; if ((channel != null) && (channel.State == CommunicationState.Opened)) channel.Close(); } }