我有常规的 net.tcp WCF 服务客户端和常规的 net.tcp双工(即带有回调)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
许多故障后重新连接。然而,几乎相同但双工BarServiceClient
仅从第一个BarServiceClient
实例接收故障事件,即一次。
为什么只有双工的第一个实例BarServiceClient
得到故障事件?有什么解决方法吗?
一个类似的未回答问题:WCF Reliable session without transport security will not faulted event on time