My application is using the net.tcp WCF service with a callback channel. For some reason I’m not able to send callbacks on event. Here’s what I’m doing (all code server-side):
On initialization:
OperationContext Context { get; protected set; }
...
Context = OperationContext.Current;
On event:
var callback = Context.GetCallbackChannel<IServiceCallbackContract>();
callback.SomeMethod();
This fails on SomeMethod() with following exception: {"Cannot access a disposed object.\r\nObject name: 'System.ServiceModel.Channels.ServiceChannel'."}
Apparently, something disposes callback channel, even though client still able to talk to server using direct (non-callback) channel. This is pretty weird. Which object am I supposed to hold on to in order to issue a callback? Is there a certain thread this must be running in?
The issue has been resolved as my error. The callbacks worked as designed, except some were stale, which when called were throwing exceptions. Since I wasn’t try/catching them, whole event was breaking on those stale callbacks :(.
Thanks to everyone who tried to answer my question.