开发者

Passing parameters in windows service

I want to develop a windows service which will be accepting a datatable from an aspx page. Both the windows service and the website are hosted on same machine.

Also I need to set a date and time on which this service is to work. this date and time are to change according to cust开发者_StackOverflow中文版omer needs. once again the date and time are to be fed from the aspx page.


The question is a bit broad, meaning it's hard to give a good example with a code sample unless you're a bit more specific about what you have already figured out, and what you need help with. Based on that, I'm guessing you're not sure where to start.

Two possibilities:

Simple: Have the ASPX page and the server both point to the same database. In order for the aspx page to send data to the service, the ASPX page should update the database; the service should read from it. Just set the service up to poll periodically. You can also store you r dates in the DB and have the ASPX page update the dates.

More advanced: Use WCF (Windows Communication Foundation) to allow the service to listen for requests from the ASPX page. (Google WECF for example code). You can pass DataSets as parameters into functions, even using WCF.


http://www.codeproject.com/KB/webservices/myservice.aspx

http://www.codeproject.com/KB/shell/ScheduledTaskWizard.aspx


Like any other executable, Windows service has Main method with parameters, if you want to pass some data to service when it starts, you can use that parameters, for example you can dump dataset to xml file and pass the path of that file on start

 static void Main(string[] args)
 {
            // Do something with args array, but il make sure its not null first.
 }

But if you want to pass parameters during execution time, you can use WCF Windows Service host


It sounds like the service should be pretty much running all the time (every minute, perhaps) and when it runs all of its logic is wrapped in a single conditional which checks the database to see if it's "supposed to run now." The web page would be maintaining that data in the database.


If you write your service to run constantly, you can use the FileSystemWatcher to look for an xml file that the aspx page can generate (probably not the most secure since that means there will be a directory someone can write to using a web page).


Put a WPF endpoint in your service?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜