문제
WCF 클라이언트의 재 연결 논리를 구현하려고합니다. 현재 채널이 결함 상태에 들어간 후 새 채널을 만들어야한다는 것을 알고 있습니다. 나는 채널 결함 이벤트 핸들러에서 이것을했다 :
internal class ServiceClient : DuplexClientBase, IServiceClient
{
public ServiceClient(ICallback callback, EndpointAddress serviceAddress)
: base(callback, MyUtility.GetServiceBinding("NetTcpBinding"), serviceAddress)
{
// Open the connection.
Open();
}
public void Register(string clientName)
{
// register to service
}
public void DoSomething()
{
// some code
}
}
public class ClientApp
{
private IServiceClient mServiceClient;
private ICallback mCallback;
public ClientApp()
{
mServiceClient = new ServiceClient( mCallback, new EndpointAddress("someAddress"));
mServiceClient.Register();
// register faulted event for the service client
((ICommunicationObject)mServiceClient).Faulted += new EventHandler(ServiceClient_Faulted);
}
void ServiceClient_Faulted(object sender, EventArgs e)
{
// Create new Service Client.
mServiceClient = new ServiceClient( mCallback, new EndpointAddress("someAddress"));
// Register the EI at Cell Controller
mServiceClient.Register();
}
public void DoSomething()
{
mServiceClient.DoSomething();
}
}
그러나 내 단위 테스트에서는 여전히 "통신 객체, System.ServiceModel.Channels.ServiceChannel은 결함 상태"예외이므로 통신에 사용할 수 없습니다.
콜백 채널이 여전히 결함이있을 수 있습니까? 그렇다면 어떻게 콜백 채널을 교체 할 수 있습니까?
해결책
지금까지 나는 WCF 연결을 결함으로 재현해야한다는 것을 경험했습니다. 그렇지 않으면 복구 할 방법이없는 것 같습니다. 결함이 발생할 때,이 방법은 정상화되는 것처럼 보이지만, 현재 요청이 진행됨에 따라 WCF 연결을 발사하고 정리하는 경우가 종종 있습니다.
몇 가지 제안 사항 : - 시간 초과 관련이라면, 마지막으로 전화를 한 시간과 타임 아웃 값이 포함 된 일정한 일정을 추적하십시오. 비 활동으로 인해 WCF 연결이 삭제되면, 그것을 떨어 뜨리고 재현하십시오. ~ 전에 당신은 와이어를 통해 요청을 보냅니다. - 다른 점은, 결함 핸들러를 다시 구하지 않는 것처럼 보입니다. 즉, 첫 번째 결함이 처리 될 수 있지만, 두 번째로 결함이 있으면 핸들러가 없으면 새 새로운 것이 첨부되지 않았습니다.
도움이 되었기를 바랍니다
다른 팁
결함이있는 이벤트 핸들러에서 mserviceclient.abort를 호출하여 통신 채널을 재설정하려고 했습니까?
편집하다:
복구 코드에서 McAllback 객체를 다시 이용하지 않는다는 것을 알 수 있습니다. 새 인스턴스에 할당해야 할 수도 있습니다.