Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CommunicationState listener?

Tags:

c#

events

wcf

Does anyone know of a way to create a listener for a proxy so that when the CommunicationState has changed I can invoke an action or a method?

An example, I want to update my WCF service for a code change. Since the application is in its early development code changes are very frequent. However, instead of annoying my employees with an email tell them that hey they need to restart their application. I would rather avoid them having to restart the app and having to send them an email. I would rather write a listener that looks at the communication state of a service and if it has changed to a faulted stated then attempt to reconnect.

Edit

Maybe some more context here.

InstanceContext context = new InstanceContext(this);
Subscriber = new SubscriptionService.MySubscriptionServiceClient(context);
Subscriber.Subscribe("");

So basically I want to know when the subscription service has stopped so that I can attempt to reconnect every 60 seconds or so. I tried looking for an event in the Subscriber service but I didn't see anything. Would I need to implement something on the service end?

Thanks

like image 243
meanbunny Avatar asked Sep 05 '26 08:09

meanbunny


1 Answers

You can use the Faulted event available on the InnerChannel property of your generated client class. The State property of the client class is just a wrapper for InnerChannel.State, so this should work as you desire.

(For reference, you can also use the similarly named event on ChannelFactory<TChannel> if you are creating communication channels in code rather than using generated proxies.)

like image 155
Alan Avatar answered Sep 06 '26 23:09

Alan