none
WCF calling Callback(from server) in a loop doesn't fire up the client callback implementation RRS feed

  • Question

  • Hi There,

    I have implemented a duplex WCF using netTcpBinding, Callback mechanism is working fine for the first time but during second call of call back method nothing fires up in client, Please let me know if you have any clue.

    Server Code:

    public void IWillCallBack()
            {
                var callbackChannel = OperationContext.Current.GetCallbackChannel<ICallback>();
                var com = (ICommunicationObject)callbackChannel;

                com.Closing += new EventHandler((object sender, EventArgs e) =>
                {
                });

                com.Faulted += new EventHandler((object sender, EventArgs e) =>
                {
                });

                Task.Factory.StartNew(() =>
                {
                    for (int i = 0; i < 10; i++)
                    {
                        Thread.Sleep(1000);
                        Console.WriteLine(com.State);
                        callbackChannel.CallMeBack(String.Format("Test ID {0}...", i));
                    }
                });
            }

    Client Code:

     private static void DuplexServiceDemo(IDoWork proxy)
            {
                proxy.IWillCallBacl();
            }

     public class CallBack : ICallback
        {
            public void CallMeBack(string sesssionId)
            {
                Console.WriteLine(sesssionId);
                Console.ReadKey();
            }
        }

    Please not first time callback does trigger  CallMeBack in client , but when 2n3, or 3rd... loop runs nothing happens in client.

    Thanks in Advance!!! 


    deepak

    Saturday, January 14, 2017 4:50 AM

All replies

  • Hi Deepak,

    Could you share us the reason you used “Console.ReadKey();” in client side?

    For your issue, I suggest you comment out this line “Console.ReadKey();” in client code.

    public class CallBack : ICallback
         {
             public void CallMeBack(string sesssionId)
             {
                 Console.WriteLine(sesssionId);
                 //Console.ReadKey();
             }
         }

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 16, 2017 5:34 AM
  • Hi Deepak,

    Did above suggestion work for you? If it did, I would suggest you mark the suggestion as answer to close this thread, if not, please feel free to let us know.

    Best Regards,

    Edward


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, February 3, 2017 1:45 AM