none
WCF Events - How To Keep Address/Handle To Client RRS feed

  • Question

  • Hello, I am new to WCF Events and I recently came across this video which in context is a little strange but it was enough to get a working example.

    http://www.youtube.com/watch?v=NO2JsLrP75E

    My question is, in my situation, I have a client that requests for something to happen from a wcf service.  The wcf service calls another internal process (exe) and it runs for an unknown amount of time(hours).  Once that process is done the (exe) notifys the wcf app that the processing is complete.

    During this hours of processing time obviously I dont have the wcf connection open.  When the (exe) calls the wcf app, how do I notify the client that it is done? (the connection was dropped)

    ---------------------------------

    now for some code

    ---------------------------------

    WCF Service - IService1.cs

    namespace AssignmentService
    {
        // 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(SessionMode=SessionMode.Allowed, CallbackContract=typeof(IMyCallbackHandler))]
        public interface IService1
        {
            [OperationContract(IsOneWay=true)]
            void KickHoffman();
    
        }
    
        public interface IMyCallbackHandler
        {
            [OperationContract(IsOneWay = true)]
            void HoffmanKicked();
    
        }
    
    }


    WCF Service - Service1.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.Text;
    using System.Threading;
    
    namespace AssignmentService
    {
        // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
        public class Service1 : IService1
        {
    
            public void KickHoffman()
            {
                //Thread.Sleep(3000);
                OperationContext.Current.GetCallbackChannel<IMyCallbackHandler>().HoffmanKicked();
    
            }
        }
    }


    Client - Program.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    using Client.ServiceReference1;
    
    
    namespace Client
    {
        class MyClass : IService1Callback
        {
            public void HoffmanKicked()
            {
                Console.WriteLine("Hoffman has been kicked");
            }
        }
    
    
        class Program
        {
            static void Main(string[] args)
            {
                InstanceContext ins = new InstanceContext(new MyClass());
                Service1Client x = new Service1Client(ins);
                Console.WriteLine("hi");
                Console.WriteLine("before:  kick hoffman was called from client");
                x.KickHoffman();
                Console.WriteLine("after:  kick hoffman was called from client");
                Console.ReadLine();
    
            }
        }
    }

    In this example, the client would invoke KickHoffman()

    Then the connection would close

    the wcf app would invoke another process

    Once that process was done it would call the wcf application again to notify that the process was done (HoffmanKicked())

    How do i get the example above to notify the client that the processing is done

    Friday, February 1, 2013 5:08 PM

Answers