WCF 이중 설정에서 클라이언트의 콜백 메서드에서 throw 된 예외를 처리하려면 어떻게해야합니까?WCF Duplex : 양방향 콜백에서 throw 된 예외를 처리하는 방법
현재 클라이언트가 잘못 모니터링하지 않는 한 오류가있는 이벤트가 발생하지 않지만 클라이언트를 사용하는 Ping() 호출 후 CommunicationException으로 인해 실패합니다. "통신 개체, System.ServiceModel .Channels.ServiceChannel은 중단되었으므로 통신에 사용할 수 없습니다. "
어떻게 처리하고 클라이언트 등을 다시 만들까요? 나의 첫 번째 질문은 그것이 일어나는 때를 발견하는 방법이다. 둘째, 어떻게 처리하는 것이 가장 좋습니까?
내 서비스 및 콜백 계약 :
이[ServiceContract(CallbackContract = typeof(ICallback), SessionMode = SessionMode.Required)]
public interface IService
{
[OperationContract]
bool Ping();
}
public interface ICallback
{
[OperationContract(IsOneWay = true)]
void Pong();
}
내 서버 구현 :
이[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
public class Service : IService
{
public bool Ping()
{
var remoteMachine = OperationContext.Current.GetCallbackChannel<ICallback>();
remoteMachine.Pong();
}
}
내 클라이언트 구현 : 그것이 나오는 것에 따라
[CallbackBehavior(UseSynchronizationContext = false, ConcurrencyMode = ConcurrencyMode.Single)]
public class Client : ICallback
{
public Client()
{
var context = new InstanceContext(this);
var proxy = new WcfDuplexProxy<IApplicationService>(context);
(proxy as ICommunicationObject).Faulted += new EventHandler(proxy_Faulted);
//First Ping will call the Pong callback. The exception is thrown
proxy.ServiceChannel.Ping();
//Second Ping call fails as the client is in Aborted state
try
{
proxy.ServiceChannel.Ping();
}
catch (Exception)
{
//CommunicationException here
throw;
}
}
void Pong()
{
throw new Exception();
}
//These event handlers never get called
void proxy_Faulted(object sender, EventArgs e)
{
Console.WriteLine("client faulted proxy_Faulted");
}
}