public static void Run <T>(CachedChannelFactory <T> factory, TimeSpan?timeout, Action <T> methodToCall) { WcfUtils.Run <T, int>(factory, timeout, delegate(T service) { methodToCall(service); return(0); }); }
public static R Run <T, R>(CachedChannelFactory <T> factory, TimeSpan?timeout, Func <T, R> methodToCall) { T t = factory.Factory.CreateChannel(); R result; using (IClientChannel clientChannel = (IClientChannel)((object)t)) { if (timeout != null) { clientChannel.OperationTimeout = timeout.Value; } CommunicationState state = clientChannel.State; bool flag = false; if (state != CommunicationState.Created) { if (state != CommunicationState.Closed) { goto IL_51; } } try { clientChannel.Open(); flag = true; } catch { clientChannel.Abort(); throw; } IL_51: bool flag2 = false; try { result = methodToCall(t); } catch (Exception error) { if (WcfUtils.IsChannelException(error)) { flag2 = true; clientChannel.Abort(); } throw; } finally { if (!flag2 && flag) { WcfUtils.CloseChannel(clientChannel); } } } return(result); }
public static void CloseChannel(IClientChannel channel) { if (channel != null) { try { channel.Close(); } catch (Exception error) { channel.Abort(); if (!WcfUtils.IsChannelException(error)) { throw; } } } }
public TReturnType Execute <TReturnType>(CachedChannelFactory <TService> factory, TimeSpan?timeout, Func <TService, TReturnType> action) { TReturnType result; try { result = WcfUtils.Run <TService, TReturnType>(factory, timeout, action); } catch (Exception ex) { Exception ex2 = WcfExceptionTranslator <TService> .TranslateException(ex, new Func <Exception, Exception>(this.GenerateTransientException), new Func <Exception, Exception>(this.GeneratePermanentException)); if (ex2 != null) { throw ex2; } throw; } return(result); }