How to determine if a client is alive for a callback in wcf?
I have a WCF implementation and I host it on a Windows Service (myself). I am using a contract inorder callback to trigger some client side events.
The question is how can I be sure or verify that the client is still alive to fire its callback event. Is there a verification mechanism? I am using .NET 3.5.
Thank.
+3
source to share
2 answers
My approach to the same problem was to create a "DefaultCallback" class that implements the callback interface and does nothing (it does not, of course, throw a Not ImplmentedException). Then you can write some code like this:
private IServiceCallBack[] GetCallBack()
{
var returnValue = new IServiceCallBack[1];
var com = (ICommunicationObject)(returnValue[0] = OperationContext.Current.GetCallbackChannel<IServiceCallBack>());
com.Closing += new EventHandler((object sender, EventArgs e) =>
{
returnValue[0] = new DefaultCallBack();
});
com.Faulted += new EventHandler((object sender, EventArgs e) =>
{
returnValue[0] = new DefaultCallBack();
});
return returnValue;
}
This way, whenever a callback client is in a closed or error state, it is replaced with a compatible object that does nothing.
0
source to share