Waiting for a response file

  • Thread starter Thread starter Keith
  • Start date Start date
K

Keith

I am writing a web service that sends work to a system that gets it's
work via XML files. This system looks for files in a particular
directory, processes the file, then leaves a response file in the same
directory. What is the best way to wait for the reponse file? Is there
a better way than going into the following loop?

while(!System.IO.File.Exists(reponseFile) {
System.Threading.Thread.Sleep(1000);
}

thanks,

-Keith
 
Check out the FileSystemWatcher class. It is designed specifically for
that purpose.

Though, if you are trying to do it within the contexts of a single web
service call, you will have to put the method to Sleep indefinitely
(waiting for the FileSystemWatcher event to wake it up).

If the process takes a long time, it probably isn't an appropriate use
of web services. Asynchronous or long running tasks are a major
weakness in the web service programming model.
Do your systems need to communicate with each other over the public
internet? If not, you probably do not need web services, as they will
bring a lot of unnecessary restrictions to your scenario. You might
want to look into a queue based system instead.

Joshua Flanagan
http://flimflan.com/blog
 
Joshau,

Thanks for the response. The directory won't be local to the hosts
needing this service. The communication will be over a LAN, not the
public internet. Can you give me more information regarding the 'queue
based system'? Maybe a link to some MSDN references?

thanks,

-Keith
 
I was referring to products like Microsoft's MSMQ.
http://www.microsoft.com/windows2000/technologies/communications/msmq/default.asp

You can get an idea of how it is used with .NET here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/bdadotnetasync2.asp
(it also references an earlier article with .NET MSMQ basics)

You may also want to explore .NET Remoting. I think you may be able to
raise an event from a remotable object, so that your calling client is
notified when the process is complete (the response file appears).

Joshua Flanagan
http://flimflan.com/blog
 
Back
Top