【发布时间】:2012-06-06 13:16:21
【问题描述】:
我有常规的 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 重新连接逻辑工作正常,在多次故障后重新连接。然而,几乎相同但双工的BarServiceClient 仅从第一个BarServiceClient 实例接收故障事件,即一次。
为什么只有双工BarServiceClient 的第一个实例会发生故障事件?有什么解决方法吗?
一个类似的未回答问题:WCF Reliable session without transport security will not faulted event on time
【问题讨论】:
-
你能发布
this.FaultedHandler方法吗? -
我已经用 FaultedHandler 代码更新了问题。
-
您现在可以发布
this.CommunicationObject属性吗?如果您可以发布整个课程,可能会更容易。 -
实际上代码被分散到三个类中。其中两个是工厂(创建方法)。第三个是重新创建连接的“观察者”类。
标签: c# .net wcf wcf-4 duplex-channel