我有正常的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
实例接收Faulted事件,即一次。
为什么只有第一个实例双工BarServiceClient
得到故障事件?有没有解决方法?
类似的非回答的问题:WCF Reliable session without transport security will not faulted event on time
你可以发布'this.FaultedHandler'方法吗? –
我用FaultedHandler代码更新了这个问题。 –
你现在可以发布'this.CommunicationObject'属性吗?如果你可以发布全班,这可能会更容易。 –