public static O ExecuteService <S, O>(ConfiguracionSistemaURLsEnumDestino destino, Func <S, O> methodName) { ChannelFactory <S> client = WCFHelper.CreateChannelFactory <S>(destino); client.Open(); S service = client.CreateChannel(); using (new OperationContextScope((IContextChannel)service)) { try { return(methodName(service)); } catch (CommunicationException ce) { throw new M4TraderApplicationException("Error de comunicación", ce); } finally { try { ((IClientChannel)service).Close(); } catch (CommunicationException) { // Ignore various exceptions regarding the Channel's current state } catch (TimeoutException) { // Ignore Timeouts } } } }
public static void ExecuteService <S>(ConfiguracionSistemaURLsEnumDestino destino, Action <S> methodName) { ChannelFactory <S> client = WCFHelper.CreateChannelFactory <S>(destino); client.Open(); S service = client.CreateChannel(); using (OperationContextScope ocs = new OperationContextScope((IContextChannel)service)) { try { methodName(service); } finally { try { ((IClientChannel)service).Close(); } catch (CommunicationException ce) { throw new MAECommunicationException("Error de comunicación", ce); } catch (TimeoutException) { // Ignore Timeouts } } } }