public void Subscribe(string address)
        {
            // note: You can also load a configured endpoint by name from app.config here,
            //       and still change the address at runtime in code.
            _channelFac = new ChannelFactory <ITimerCallbackTarget>(new BasicHttpBinding(), address);

            _timer.Elapsed += (p1, p2) =>
            {
                ITimerCallbackTarget callback = _channelFac.CreateChannel();
                callback.OnTimeElapsed(_dataToSend++);

                ((ICommunicationObject)callback).Close();

                // By not keeping the channel open any longer than needed to make a single call
                // there's no risk of timeouts, disposed objects, etc.
                // Caching the channel factory is not required, but gives a measurable performance gain.
            };
            _timer.Start();
        }
Beispiel #2
0
            public static bool ValidateTimerCallbackTarget(object o)
            {
                ITimerCallbackTarget oPtr = o as ITimerCallbackTarget;

                return((oPtr != null) && (oPtr.isValid));
            }