i have a WCF implementation and i host it within windows service(self-hosted). I use callback contract inorder to trigger some events on the client side.
The question is how i can be sure or check that client is still alive for triggering its callback event. Is there any check mechanism? I use .NET 3.5.
Thanks.
Asked
Active
Viewed 4,063 times
3

Fer
- 1,962
- 7
- 29
- 58
2 Answers
0
There isn't any inbuilt way.
Should the client not be available to process the callback then your service will either hang or throw an exception when trying to invoke the client callback (depending on the state of the callback channel).
One possible solution to this problem is here

Community
- 1
- 1

tom redfern
- 30,562
- 14
- 91
- 126
-
1i want to detect it gracefully. I dont want to make it depend on an exception thrown. Can i just cast the callback contract to ICommunicationObject and then check its state? Would it work? – Fer Apr 09 '12 at 10:33
-
I am sorry I don't know the answer to that. – tom redfern Apr 10 '12 at 11:42
-
Thank you @hugh. i will use casting the CallbackContract to ICommunicationObject and check if its state is open. By the way, a better solution will be appriciated. – Fer Apr 10 '12 at 13:49
0
My approach to the same problem was to create a "DefaultCallback" class that implements the callback interface and do nothing (it doesn't throw any Not ImplmentedException of course). Then you can write a bit of 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;
}
So, whenever the callback client is in closed or faulted state, it's replaced by a compliant object which does nothing.

Serge
- 6,554
- 5
- 30
- 56