I have two application connected by a duplex WCF connection. I works well, as long the connection is consistent.
I am checking now how to handle the re-connecting scenarios, when the connection is lost and it has to reconnect again. And I'm struggling to understand how work this out in WCF.
As far as I knew, the IChannel
is expendable, but the ChannelFactory
is expensive. So I create one factory, and then the channel. Whenever I detect the Closed
or Faulted
events in the channel, I try
to close the channel, deattach the event handlers and then create another channel.
But this approach is not working very well, because sometimes the DuplexChannelFactory<T>.CreateChannel
gets faulted as well, and throws this exception:
System.ServiceModel.CommunicationObjectAbortedException occurred
HResult=-2146233087
Message=The communication object, System.ServiceModel.InstanceContext, cannot be used for communication because it has been Aborted.
How is this possible that the factory itself gets faulted this way?
What is the right approach to handle disconnections/reconnections in WCF?