wcfクライアントの再接続ロジックを実装しようとしています。現在のチャネルが障害状態になった後、新しいチャネルを作成する必要があることを認識しています。これは、チャネル障害のあるイベントハンドラーで行いました。
internal class ServiceClient : DuplexClientBase, IServiceClient
{
public ServiceClient(ICallback callback, EndpointAddress serviceAddress)
: base(callback, MyUtility.GetServiceBinding("NetTcpBinding"), serviceAddress)
{
// Open the connection.
Open();
}
public void Register(string clientName)
{
// register to service
}
public void DoSomething()
{
// some code
}
}
public class ClientApp
{
private IServiceClient mServiceClient;
private ICallback mCallback;
public ClientApp()
{
mServiceClient = new ServiceClient( mCallback, new EndpointAddress("someAddress"));
mServiceClient.Register();
// register faulted event for the service client
((ICommunicationObject)mServiceClient).Faulted += new EventHandler(ServiceClient_Faulted);
}
void ServiceClient_Faulted(object sender, EventArgs e)
{
// Create new Service Client.
mServiceClient = new ServiceClient( mCallback, new EndpointAddress("someAddress"));
// Register the EI at Cell Controller
mServiceClient.Register();
}
public void DoSomething()
{
mServiceClient.DoSomething();
}
}
しかし、単体テストでは、「通信オブジェクトSystem.ServiceModel.Channels.ServiceChannelは、障害状態にあるため、通信に使用できません」という例外が発生します。
コールバックチャネルにまだ障害が発生している可能性はありますか?はいの場合、コールバックチャネルを置き換えるにはどうすればよいですか?