通常の 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
だけ Faulted イベントを受け取ります。BarServiceClient
duplex の最初のインスタンスだけBarServiceClient
が faulted イベントを取得するのはなぜですか? 回避策はありますか?
同様の未回答の質問:トランスポート セキュリティのない WCF の信頼できるセッションでは、時間どおりにイベントが発生しません。