locked
how to schedule a WCF service that ...i want to run as windows service ? RRS feed

  • Question

  • hi...

    i have created windows service according to the MSDN artical....http://msdn.microsoft.com/en-us/library/ms733069.aspx.....as it is just have change methods....

    windows service run contiguously from the OS boot to the suthdown... 

     but now i want to run this service at every 15 minutes ...

    how to can i modified this service ?

    how to can i implement interval thing in this service ... without using windows task scheduler    ?

    using System;
    using System.Threading;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ComponentModel;
    using System.ServiceModel;
    using System.ServiceProcess;
    using System.Configuration;
    using System.IO;
    using System.Configuration.Install;
    
    
    namespace service_test_interval
    {
        [ServiceContract(Name = "http://service_test_interval")]
        public interface Itet_interval
        {
            [OperationContract]
            void print_time();
        }
    
        class print_time_infile:Itet_interval
        {
           
            public void print_time()
            {
                DateTime dt = DateTime.Now;          
    
                using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"D:\print_time.txt", true))
                {
                    file.WriteLine(dt.ToString());
                }
    
            }
        }
    
       
        class interval_service : ServiceBase
        {
            ServiceHost serviceHost=null;
            public interval_service()
            {
                ServiceName = "WCF win interval_service ";
            }
    
            static void Main()
            {
                ServiceBase.Run(new interval_service());
            }
    
    
    
            protected override void OnStart(string[] args)
            {
                if (serviceHost != null)
                {
                    serviceHost.Close();
                }
    
                         serviceHost = new ServiceHost(typeof(interval_service));
    
               
              
                serviceHost.Open();
            }
    
            protected override void OnStop()
            {
                if (serviceHost != null)
                {
                    serviceHost.Close();
                    serviceHost = null;
                }
            }
    
    
        }
    
        [RunInstaller(true)]
        public class ProjectInstaller : Installer
        {
            private ServiceProcessInstaller process;
            private ServiceInstaller service;
    
            public ProjectInstaller()
            {
                process = new ServiceProcessInstaller();
                process.Account =    ServiceAccount.LocalSystem;
                service = new ServiceInstaller();
                service.ServiceName = "WCF win interval_service";
                Installers.Add(process);
                Installers.Add(service);
            }
        }
     
    
    }
    

    Thursday, July 26, 2012 11:17 AM

Answers

  • Indeed, I have already answered to similar question. Please find here.

    If this post answers your question, please click Mark As Answer. If this post is helpful please click Mark as Helpful.

    Regards,
    Nair S

    • Marked as answer by LeoTang Thursday, August 2, 2012 7:20 AM
    Thursday, July 26, 2012 11:31 AM