Search code examples
c#wcfcallbackwcf-binding

callback continue


in the code below (wcf server) , if the client disconnects i want the code to continue processing. Right now it jumps to the catch statement and stops processing. The purpose of the callbacks will eventually to update the client on progress of a request but the client can disconnect if he wants at any stage and i want processing to continue.

   public void ChatToServer(string texttoServer) // send some text to the server
        {
            Logging.Write_To_Log_File("Entry", MethodBase.GetCurrentMethod().Name, "", "", "", 1);

            try
            {

                Thread.Sleep(5000);
                IMyContractCallBack callback = OperationContext.Current.GetCallbackChannel<IMyContractCallBack>();
                callback.callbacktoServer("Progress is 20% complete");
                // Some extremely important processing
                ....
                callback.callbacktoServer("Progress is 40% complete");
                // Some extremely important processing
                ....
                callback.callbacktoServer("Progress is 60% complete");
                // Some extremely important processing
                ....
                callback.callbacktoServer("Progress is 80% complete");    

                // Some extremely important processing
                ....
                callback.callbacktoServer("Progress is 100% complete");                                   
            }
            catch (Exception ex)
            {

            }

        }

Solution

  • If I'm understanding you correctly, all you need to do is trap communications errors from your callback call and ignore them - you'll probably want to put the callback call in its own method so that you don't have to repeat the exception handling logic for each progress notification site.