1

I've been searching for a few hours for a possible solution and advice about my scenario.

I have an XML file which is created when we request it from the server. There are several services which then look at the XML file and consume it's data.

I've written a WCF which will update the XML file. What I'd like to do is to set up a Windows Service to call the WCF every 10 seconds. This will force the XML file to be updated every 10 seconds.

I am struggling to find how to create the windows service and install it. Also is this the best approach? I have used scheduled tasks on the server before - but this only offers 1 minute intervals. I could write the script to sleep and re-call istself every 10 seconds I suppose?

Thanks for any info.

Matt Facer
  • 3,073
  • 11
  • 45
  • 91
  • I did exactly this and have the code at home. I will check back later and post it if you are still looking. – Fred Sep 05 '12 at 15:23
  • this would be great if you have it!! - thanks :) – Matt Facer Sep 05 '12 at 16:13
  • I've got the service running - just need to work out how to do the timer & WCF calls – Matt Facer Sep 05 '12 at 16:14
  • 1
    Sorry Matt I totally forgot to post last night! However these two link tell you what you need to know... http://stackoverflow.com/questions/246697/windows-service-and-timer http://www.thebestcsharpprogrammerintheworld.com/blogs/create-and-consume-a-wcf-windows-communication-foundation-service.aspx Hope they help – Fred Sep 06 '12 at 07:17
  • Thanks Fred. I've followed the two and I am just trying to get the service called. So far that's not working - but the timer is ok! – Matt Facer Sep 06 '12 at 09:25

2 Answers2

2

There are plenty of tutorials on how to create and install Windows Services. This is the one I used a few years ago to learn: http://www.codeproject.com/Articles/106742/Creating-a-simple-Windows-Service

Best is to give it a go, and come back here with specific questions when you get caught on something.

    protected override void OnStart(string[] args)
    {
        // this is where you'd put the logic that does the work (as per the example)
        // create a Timer object to execute your desired functionality 
        // every 10 seconds.
    }
DaveDev
  • 38,095
  • 68
  • 199
  • 359
0

You say you have several services that look at the XML file. What are these? Windows services, or front end WCF services? If you have control over the services that are consuming the XML, perhaps one of them could be responsible for obtaining and updating it too.

This answer to a post earlier today contains a fine example of how you can create a Windows service with minimal fuss. If you need an installer though, you're into more complicated territory.

Community
  • 1
  • 1
Olly
  • 5,716
  • 27
  • 57