I have a win forms client that accesses a wcf service for a long running operation. The service exposes subscribe and unsubscribe methods. When a client calls the subscribe method, service generates new guid for it and gets the current callback context, saves this guid and callback context in a client Dictionary and returns the Guid. On user request, client call service with this guid to start the long operation. Once the service finishes the operation it gives a callback to the client. the client then retrieves the processed data from the service.
The error I get sometimes when doing a callback is
The operation ‘OnServiceCallback’ could not be completed because the sessionful channel timed out waiting to receive a message. To increase the timeout, either set the receiveTimeout property on the binding in your configuration file, or set the ReceiveTimeout property on the Binding directly.
The part that I am not able to understand is that this happens very inconsistently. Most of the times it happens after the client and the service have been running for some time.
I am a beginner in wcf service and welcome any suggestions to solve this error.
I was able to figure the answer to the error by doing some good old trial and error. The callback was failing because the
OperationContext.Currentobject that I was trying to use was null. This was because I was trying to access theOperationContext.Currentobject on a thread which was different from the service thread. So to solve that I am now accessing theOperationContext.Currentobject in the service thread and then passing thecallbackContextas a parameter to the external processing logic which actually needs to use it.