The question,
I have a web application - .net 4.
The client is having a requirement that he want to send email to his users on a regular basis about his new courses etc.
The webapplication created will hosted on a "Shared hosting environment" with no excess to windows services - file system other than the web root folder through FTP.
The PROBLEM is that ...
Due to shared hosting i cannot create a windows service for him which will check the database - if there are any scheduled mail to send every 5 min.
So my question is - Is there anyway i can run a wcf web service or any other web based service or page or handler which can keep running and automatically checks the database for any new scheduled mails - if yes start sending it automatically in an different thread.
Any different suggestion or answers are also very much welcomed. Thanks SO Experts.
Create a webmethod in WCF that needs to be called, and that can be reached through a url, for example:
http://www.example.org/checkandsend/email/
Add a new scheduled task on your own PC, that calls that URL every five minutes. Voila.
Rick Strahl: Forcing an ASP.NET Application to 'stay alive'
Related
My requirement is to send emails within the web application from an external server that takes around 4 to 5 seconds on average to process and send the confirmation email. I do not want the user to wait for this, so i trigger a console application with Process().StartInfo.Start() and it does it in background. The question is how much i can rely on this as during normal days the application sends around 10 thousand emails daily and in high traffic days it may surpass 80 thousand. What possible issues/problems the application or server may run into? Is there any better solution for this?
You can use following method to achieve this:
Create a .aspx page and write you business code here (e.g. email
send)
Where required, call this page using Javascript along with parameters in querystring. You can create an image element and set its source to that page.
var img = new Image();
img.scr = "perform-operation.aspx?[parametervalues]";
Thank you
Console application has drawback, if you plan to invoke console application for each email separately, any new process takes long to load and clean up, this is too much overhead on cpu. Instead, the best alternative is to host another website in IIS, this new website will have its own Application Pool, which will create and host process. IIS will shutdown the process if no request is served. You can setup Web Farm by running more worker process per application.
Other alternative is to run console or windows service all the time, let it be in the memory but has a web service host listening for email requests, if a request is received from your web application, this background service will send email on new thread and go back on waiting state. Basically it is a self hosted WCF service. This is quite same as hosting another website on IIS.
I prefer IIS based hosting as it is easy to setup, does not require any extra permissions and in future, to scale horizontally, you can easily move this mail service to other server.
I'm trying to consume a Java Web Service from third party, so i dont have any control over it. I have a pfx file which is password protected, and i installed it in my development box.
This is the code i'm using:
var proxy = new MyServiceReference.WsaaServerBeanService();
var result = proxy.login("test");
I'm getting System.Net.Sockets.SocketError.TimedOut exception when invoking the login web method. The first thing that come to my mind is an authentication issue. Apart from installing the pfx, do i need to send some other info to the web server to authenticate?
System.Net.Sockets.SocketError.TimedOut
Does not indicate an authentication issue, it indicates that you either are not able to contact the remote web service endpoint, or you are and the service is taking too long to respond. Make sure you can actually hit the endpoint from your machine via telnet, a web browser etc...
Authentication failures will usually return immediately.
I am new to the WCF model, but I have created a service, that seems to work in VS2010
Now I would like to access this windows service from an asp.net application. The reason behind this is: I want to be able to call the service to connect via SSH to a server, and keep that connection open (as I did in a Windows Forms app)
Any ideas on how to go about doing this? I tried it with an IIS hosted service, but the connection is lost each time the request finishes.
At least in VS2010 with the tester, I can invoke my connect function, then invoke other functions to query data, then disconnect.
FYI, the local Windows Service and IIS are on the same box.
WCF services by default create a new instance for each request. There are other models, although I'm not sure they will manage as long running a process as you want. This article has some good info on managing sessions: http://msdn.microsoft.com/en-us/magazine/cc163590.aspx
Alternatively, why not use a technology like workflow foundation, that was designed to run / persist / re-awaken long-running processes? http://msdn.microsoft.com/en-us/library/ee342461.aspx
Small question, was anyone able to control iTunes through any local webdeployment?
Most preferable through a hosted IIS WCF service?
I've tried on my Windos 7 with IIS7.5 and when I set the Process Model - Identity to 'Local System' on the IIS apppool containing the WCF service, I see the iTunes.exe popping up in the Task Manager.
But iTunes doesn't come 'alive' - no visual shell and even though the iTunesApp object is initialized in my WCF Service code, perfomring any actions on it won't work.
Side not, running the same service through Visual Studio 2010 debug mode, everything works just great!
UPDATE *
I was trying to communicate to iTunes through my windows phone and I thought of going round that with a website/service... but with the new Mango update we can do TCP sockets native on the phone! SO I'll try that route.
The reason service does not show any UI windows is becuase of Session Isolation. Your service (IIS application pool process) is running in session 0. Your desktop is attached to session 1 (or some other number if more than one user is logged on on this machine).
There are couple of workarounds to allow services to show UI to user:
1. You can mark service with option "Allow service to interact with desktop". This only works for services that are running as local system. This option is deprecated, should only be used for compatibility with legacy services.
2. Service can launch an intermediate process in user session and communicate to it.
If you don't want to interact with iTunes, and only want to lanch it in user session, what you need to do is:
Obtain name of windows station the user is running. You can use windows terminal services API for that. You will have to be creative to figure out which user session is currently active (if there is more than one). You probably also want to query user security token, so that process is run as a user, and not as a local system.
Call CreateProcessAsUser and pass STARTUPINFO structure. Set lpDesktop field in STARTUPINFO to point to window station you identified.
The reason this works when debugging in Visual Studio 2010 is because you're running VS under your login and your login has a visible desktop that iTunes can interact with.
If you launch from a process running under a service account then yes you'll see the executable in task manager but the iTunes won't have a visible desktop to interact with.
In my project, i have used schedule control. It can be able to fix appointments for single/several users. I have configured of sending mails to the selected users through save /edit appointment actions.
Now i need to send mails automatically using windows service for every 30mins to the selected users during appointment time. for e.g. if appointment spans for a user 2pm to 4pm, mail need to be sent for every 30mins bet 2pm to 4pm automatically.
I have installed windows service. But i don't know how to connect my MVC web project with the windows service. I'm using MDF database in my web project. I don't know how to process those datas in window service.
Please suggest me some way. I'm totally new to MVC and Windows service.
Thanks in advance.
The issue outlined in your question sounds like a good use of the Revalee open source project.
Revalee is a service that allows you to schedule web callbacks to your ASP.NET MVC application. Revalee manages task persistence and scheduling using a Windows Service, but leverages your ASP.NET MVC application to handle the processing effort (i.e., "the work"). In your case, your would use your MVC application to send an automated email messages to a user when the MVC application was called back by Revalee.
The following shows an overview of the workflow used by an MVC application with Revalee:
(source: sageanalytic.com)
When an appointment is scheduled, your application would register a callback action with Revalee. This would include a date & time to call the MVC application back as well as the URL to call. Therefore to register a callback with Revalee you might include the following method in your MVC application.
private void ScheduleAppointmentReminderEmail(int appointmentId)
{
// The DetermineAppointmentReminderTime() method is your private method
// which returns an appointment's next reminder time as a DateTimeOffset.
DateTimeOffset callbackTime = DetermineAppointmentReminderTime(appointmentId);
// The callback should at the task's end time
Uri callbackUrl = new Uri(
string.Format(
"http://mywebapp.com/Email/SendAppointmentEmail/{0}",
appointmentId
)
);
// Register the callback request with the Revalee service
RevaleeRegistrar.ScheduleCallback(callbackTime, callbackUrl);
}
When your MVC application receives the callback, the SendAppointmentEmail action might look like:
[AllowAnonymous]
[CallbackAction]
public ActionResult SendAppointmentEmail(int appointmentId)
{
// TODO 1. Validate the appointmentId,
// 2. Lookup the appointment's information, &
// 3. Send the email message
// ...
return new EmptyResult();
}
The Revalee website has a complete API Reference as well as instructions on how to install and configure the Windows Service. The service is available for easy deployment & intallation at Chocolatey, while MVC client libraries ready for use in Visual Studio are available at NuGet. (There are non-MVC client libraries too.) Naturally, as an open source project, Revalee's complete source code is available on GitHub.
Finally, in case it was not clear above, the Revalee Service is not an external 3rd party online scheduler service, but instead a Windows Service that you install and fully control on your own network. It resides and runs on a Windows server of your own choosing where it can receive callback registration requests from your ASP.NET MVC application.
I hope this helps. Gook luck!
Disclaimer: I was one of the developers involved with the Revalee project. To be clear, however, Revalee is free, open source software. The source code is available on GitHub.
I did´t understand your question very well, however, the connection point between the web application and the windows service is the database. Your web application writes in the database the pending appointments. Then, your windows service checks every 30 minutes, for example, if there is any pending appointment for which it has to send the emails. If it finds out that it has to send some emails, it sends them and marks the entry in the Db as completed (meaning that it has sent the notifications). You can also use Quartz.net as I mentioned in another answer, but a windows service is also a good solution.
You don't have to use the windows service. Everything you described can be solved by using the application built-in HttpModule aka Global.asax .
The high level concept is to keep the HttpApplication running, and within the life time of the application, which is your MVC web application deployed to IIS. This is to prevent the Application_End firing due to inactivity default at 20 minutes.
Once you kept the application running, you can schedule the preferred time interval to talk to database and send emails. This would be the simplest way to do your task.
There is a codeproject sample: http://www.codeproject.com/KB/aspnet/ASPNETService.aspx