2012-06-01 6 views
2

나는 정기적 인 net.tcp WCF 서비스 클라이언트와 정기적 인 net.tcp duplex (콜백 포함) WCF 서비스 클라이언트를 가지고 있습니다. 서비스가 실패한 경우에 대비하여 연결을 끊임없이 다시 인스턴스화하는 로직을 구현했습니다.듀플렉스 채널 두 번째 연결 시도시 오류 이벤트가 발생하지 않습니다.

는 그들은 정확히 같은 방식으로 만들어집니다

FooServiceClient Create() 
{ 
    var client = new FooServiceClient(ChannelBinding); 
    client.Faulted += this.FaultedHandler; 
    client.Ping(); // An empty service function to make sure connection is OK 
    return client; 
} 

BarServiceClient Create() 
{ 
    var duplexClient = new BarServiceClient(new InstanceContext(this.barServiceCallback)); 
    duplexClient.Faulted += this.FaultedHandler; 
    duplexClient.Ping(); // An empty service function to make sure connection is OK 
    return duplexClient; 
} 

public class Watcher 
{ 
public Watcher() 
{ 
    this.CommunicationObject = this.Create(); 
} 

ICommunicationObject CommunicationObject { get; private set; } 

void FaultedHandler(object sender, EventArgs ea) 
{ 
    this.CommunicationObject.Abort(); 
    this.CommunicationObject.Faulted -= this.FaultedHandler; 
    this.CommunicationObject = this.Create(); 
} 
} 

FaultedHandler() 채널을 중단하고 은 위의 코드를 사용하여를 다시 만듭니다.

FooServiceClient 재 연결 논리는 정상적으로 작동하며 많은 오류가 발생한 후에 다시 연결됩니다. 반면, 거의 동일하지만 양방향 인 BarServiceClientBarServiceClient 인스턴스의 오류 이벤트 (예 : ) 만받습니다.

듀플렉스 BarServiceClient의 첫 번째 인스턴스 만 오류가 발생하는 이유는 무엇입니까? 해결 방법이 있습니까?


유사한 비 대답 질문 : WCF와의 전쟁에 WCF Reliable session without transport security will not faulted event on time

+0

'this.FaultedHandler' 메소드를 게시 할 수 있습니까? –

+0

FaultedHandler 코드로 질문을 업데이트했습니다. –

+0

이제'this.CommunicationObject' 속성을 게시 할 수 있습니까? 전체 수업을 게시 할 수 있다면 더 쉽습니다. –

답변

1

이 후 일 나는 해결 방법을 발견했다.

때때로 WCF는 Faulted 이벤트를 발생 시키지만 때로는 그렇지 않습니다. 그러나 특히 Abort() 호출 후 Closed 이벤트가 발생합니다.

그래서 나는 Closed 이벤트를 효과적으로 발생시키는 FaultedHandlerAbort()을 호출합니다. 그 다음에 ClosedHandler은 다시 연결을 수행합니다. 프레임 워크별로 Faulted이 실행되지 않을 경우 Closed 이벤트가 항상 발생합니다.

BarServiceClient Create() 
{ 
    var duplexClient = new BarServiceClient(new InstanceContext(this.barServiceCallback)); 
    duplexClient.Faulted += this.FaultedHandler; 
    duplexClient.Closed += this.ClosedHandler; 
    duplexClient.Ping(); // An empty service function to make sure connection is OK 
    return duplexClient; 
} 

public class Watcher 
{ 
public Watcher() 
{ 
    this.CommunicationObject = this.Create(); 
} 

ICommunicationObject CommunicationObject { get; private set; } 

void FaultedHandler(object sender, EventArgs ea) 
{ 
    this.CommunicationObject.Abort(); 
} 

void ClosedHandler(object sender, EventArgs ea) 
{ 
    this.CommunicationObject.Faulted -= this.FaultedHandler; 
    this.CommunicationObject.Closed -= this.ClosedHandler; 
    this.CommunicationObject = this.Create(); 
} 
} 
관련 문제