Sunday, June 8, 2008

ASP.NET Task Scheduler:
Windows Service / Web Service or Web Page


















The C# (Visual Studio 2008) solution is here:

The application works. You will have to download the source code, re-import your service method and re-compile. I will work on the project when I have time to make it easier to implement, but it provides a good start towards a solution.
Since the Web Service and re-compilation made it more difficult, I thought I could simplify by making a call to a Web Page instead and use the Page_Load event. I tried to use the WebClient object which worked from a Windows Form but would not work from a Windows Service, even with Administrative privledges. I ended up using some code from a site:


Stream str = null;
HttpWebRequest wReq = (HttpWebRequest)WebRequest.Create("http://www.site.com/tick.aspx");
HttpWebResponse wRes = (HttpWebResponse)(wReq).GetResponse();
str = wRes.GetResponseStream();

I was experiencing a error:

The operation has timed out
You must call either the Stream..::.Close or the HttpWebResponse..::.Close method to close the stream and release the connection for reuse. It is not necessary to call both Stream..::.Close and HttpWebResponse..::.Close, but doing so does not cause an error. Failure to close the stream will cause your application to run out of connections.
So, I added...

str.Close();
str = null;
wRes.Close();
wRes = null;
wReq = null;

It works....


Added 8/25/2008
I zipped up the Source which can be found in this folder:




3 comments:

Pete Traversy said...

Nifty! Almost perfect :-) However, I've been struggling with it for most of the morning.

1. The config app won't run w/o Telerik controls installed (which I don't have at the moment)
2. So I manually modified the config xml file to point to my webservice, but I still get the event error:
**********
PingUrlError: System.Web.Services.Protocols.SoapException: Server did not recognize the value of HTTP Header SOAPAction: http://Com.StockerWeb.WebService/Tock.
**********

I was going to try to rebuild the project to address these issues, but I can't figure out an easy way to simply download the source in one go - you need to copy and paste the code from an html page (from what I can tell).

Oh well...

Anonymous said...

Nice solution! How can we download the source code in one zipped file?

Tom Gilkison said...

pete traversy was able to get the code working for his site. I have zipped the source for a single download and made a link from this page.

Check This Out!

More Links to Good Information