에 동의 마지막 대답은, 일단 실패하면, 당신은 중단해야합니다.
이
public static void Use<TServiceInterface>(TServiceInterface proxy, Action handler)
{
Type proxyType = typeof(TServiceInterface);
IClientChannel channel = (IClientChannel)proxy;
try
{
handler();
_logSource.Log(LogLevel.Debug, string.Format("Closing client channel for '{0}' ...", proxyType.Name));
channel.Close();
_logSource.Log(LogLevel.Debug, string.Format("Client channel for '{0}' closed.", proxyType.Name));
}
catch
{
if (channel.State == CommunicationState.Faulted)
{
_logSource.Log(LogLevel.Debug, string.Format("Aborting client channel for '{0}' ...", proxyType.Name));
channel.Abort();
_logSource.Log(LogLevel.Debug, string.Format("Client channel for '{0}' aborted.", proxyType.Name));
}
else
{
_logSource.Log(LogLevel.Debug, string.Format("Closing client channel for '{0}' ...", proxyType.Name));
channel.Close();
_logSource.Log(LogLevel.Debug, string.Format("Client channel for '{0}' closed.", proxyType.Name));
}
throw;
}
}
이가 그물에 이미 해결책의 약간의 수정이지만, 프록시를 처리하기위한 좋은 작품 : 우리는이 작업을 수행하려면 다음과 같이 람다의 조합 방법을 사용합니다. 그런 다음 동일한 람다 표현식에 여러 서비스 호출을 넣고 메소드에 전달할 수 있습니다.
문제는 서비스 프록시에서 함수에 대한 대리자를 가져 오는 내부 함수가 있고 통신 예외가 throw되지 않을 때까지 함수를 반복적으로 실행한다는 것입니다 (자동 재 연결 구현). 따라서이 솔루션에서 함수는 각 실행 시도에 대한 프록시의 인스턴스를 만들고 호출자에게 업데이트 된 인스턴스를 반환해야하므로 닫힌 프록시를 보유하지는 않습니다 ... 추종 : -/ – Andy