none
What can I do to receive a callback Response WCF RRS feed

  • Question

  • Hi

    I got a service in WCF that make callbacks to clients.

    What can I do for know if the client received the callback?

    Is there callback responses?

    Or I need to make one method for callback confirmation? (e.g. the client send callback, and then it wait for a call confirmation method)

    • Moved by Amanda Zhu Friday, July 5, 2013 6:36 AM move to a more appropriate forum
    Wednesday, July 3, 2013 10:28 PM

Answers

  • Hi

    Please See the below implementation :

    ICounterService.CS

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    namespace CallBack_server
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
        [ServiceContract]
        public interface ICounterService
        {
            [OperationContract]
            int Increment();
            [OperationContract]
            int Decrement();
        }
        [ServiceContract(CallbackContract = typeof(IResult))]
        public interface ICounterService1 // for client to call the service
        {
            [OperationContract(IsOneWay = true)]
            void Start();
        }
        [ServiceContract]
        public interface IResult // for callback (service will use it to call client)
        {
            [OperationContract(IsOneWay = true)]
            void SendCount(int count);
        }
    }

    in CounterService.cs

    using System.ServiceModel;
    namespace CallBack_server
    { 
        [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
        public class CounterService : ICounterService, ICounterService1
        {
            public void Start()
            {
                while (true)
                {
                    System.Threading.Thread.Sleep(2000); // 2 secs
                    count++;
                    // send the count value to the client (callback: service calls client)
                    OperationContext.Current
                        .GetCallbackChannel<IResult>()
                        .SendCount(count);
                }
            }
            private int count = 0; // instance field (field that becomes part of the service object)
            public int Increment()
            {
                if (count > 3)
                    throw new FaultException("Cannot be > 3");
                return ++count;
            }
            public int Decrement()
            {
                return --count;
            }
        }
    }

     

    yes, we need to add proxy method for Callback implementation

    Thursday, July 4, 2013 11:00 AM