Reputation: 1520
Now, I have one ASP.NET MVC application. I have the several methods in ASP.NET MVC application which retrieve data from external windows desktop(not mine) application (by tcp/ip). And now I want to move this methods to external service(program), also other methods( send email messages and other proccesses which now runing in separate thread). This is my first experience with web services/wcf. And, what is the better way to do that: wcf, web service, win service?
Thanks
MORE DETAILS:
In ASP.NET MVC app I get various information from external desktop (not mine) application(by TCP/IP). For example in this program creates events: movies, sports, theaters, and schedule for them. Also, how many seats left for a particular session and many other.
Different types of informations can be obtained in various ways. Sometimes, I check every minute that there are updates( list of events, shedules). Sometimes I need every minute to get other information for cahcing(how many seats left for session). Therefore, I have many tasks are performed in a separate thread and approach described bellow.
For updates from external win program I using the following approach:
protected void Application_Start()
{
AddTask("UpdateFromExternalProgram", "60", 60);
}
private static CacheItemRemovedCallback _onCacheRemove = null;
public static void AddTask(string name, string value,int seconds)
{
_onCacheRemove = new CacheItemRemovedCallback(CacheItemRemoved);
HttpRuntime.Cache.Insert(name, value, null,
DateTime.Now.AddSeconds(seconds), Cache.NoSlidingExpiration,
CacheItemPriority.NotRemovable, _onCacheRemove);
}
private static void CacheItemRemoved(string key, object value, CacheItemRemovedReason reason)
{
if (reason == CacheItemRemovedReason.Expired)
{
AddTask(key, value.ToString(), Convert.ToInt32(value));
GetUpdatesFromExternalProgram();
}
}
private static void GetUpdatesFromPremiera()
{
//creates TCP/IP client, send request, and parse response
}
Also, in a separate thread sends all emails on site( registration, feedback, other information):
ThreadPool.QueueUserWorkItem(new WaitCallback(SendEmailInSeparateThread), senderInfo);
And, I want to move this functional into other app: wcf, web service or win service.
Upvotes: 1
Views: 620
Reputation: 1038710
You should avoid implementing recurring background tasks in ASP.NET applications. A Windows Service is a better candidate to implement this functionality.
Upvotes: 2