1

I have a duplex WCF service with sessions enabled, and I'm trying avoid fault state exceptions on the client.

I found several discussions arround this topic, but all I have found suggest to recreate the client proxy or channel. Non is focus in duplex services with session enabled.

My problem with that approach is that there is one session per client in the server, and each client has only one instance of the service proxy (singleton service proxy). Because it is duplex, in the client side several objects are listening to events on that service instance (messages sent from the server to the client). If the service is in faulted state, it can not be used any more. If I discard that instance and create a new one, I'm finding it hard to hook up all the event handlers again to this new instance.

Should I wrap the service and every time an object hooks up for an event, store the handler in a list (so that I can re hook it when service is recreated)? Seems to be lost of code, easy to leak memory...

Is there a way to just restart the client proxy / channel, without discarding all the proxy instance? (I'm using the VS generated proxy)

Any ideas?

Thanks, MAB

Matias
  • 33
  • 3

1 Answers1

3

You cannot restart the proxy. The only recovery from faulted state is aborting current instance and recreating the new one. On the client side you must correctly unregister everything dependent on your proxy instance, create new instance and register everything again. This whole operation must happen once you get the exception about channel in faulted state (= when you try to call the service). After recreation you must call the service again.

On the service side the instance is either already dead (that caused the faulted state of the channel) or it will die after session timeout. You must also handle faulted exception when you try to callback on the faulted channel by removing the channel from your known clients and unregistering anything dependent on that channel.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • bad news, so I will have to code all that :-( Nevertheless, this seems to be something that needs to be tackled on every application that uses a service with sessions enabled. Does anybody knows some library I can reuse? – Matias Aug 10 '11 at 23:09