Reputation: 697
I am trying to figure out the best way to call a web service on a schedule. I have been doing research for longer than I want to admit and just need some thoughts on the best way to do this, and how to start.
I have a asmx web service that I need to call every morning at a specific time to run some import processes in my application. I don't need to pass anything to it and I don't (necessarily) need to get any results back from the web service.
A lot of what I find on the internet is older technology and I am having trouble implementing any of it in my .NET 4.0/4.5 applications. I am totally lost and just need some direction to make sure I am not going about this completely wrong. I have always worked with web apps and have never done anything with Windows services or anything like them.
I was looking into Windows Services but was not having any luck. Before I fight my way through them I wanted to make sure I was even headed down the right direction. All I need to do is call this web service on a schedule from a Windows app/service/etc.
Thoughts?
EDIT**
OK, for the time being I have decided to go with a console app and have one working to call the web service. I know I initially said I didn't care about passing parameters to the web service, but now I have decided that it would be a nice addition.
This is what I currently have, but I cannot figure out how to pass parameters for the life of me.
Dim sSource As String
Dim sLog As String
Dim sEvent As String
sSource = "Import Project Information"
sLog = "Application"
sEvent = "Import Started"
If Not EventLog.SourceExists(sSource) Then
EventLog.CreateEventSource(sSource, sLog)
End If
EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.Information, 0)
Dim WebService As New Web_Service.ImportProjectInfo
Dim results As Boolean = WebService.Import()
Console.WriteLine(results)
If results = True Then
sEvent = "Import Successful"
EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.SuccessAudit, 1)
Else
sEvent = "Import Failed"
EventLog.WriteEntry(sSource, sEvent, EventLogEntryType.FailureAudit, 999)
End If
Upvotes: 0
Views: 1014
Reputation: 697
It is the easy stuff that drives us crazy!!!!!
I didn't want to change my web service to add the parameters until I found the way to pass those parameters. I didn't realize that the code I was writing was aware that I didn't have those parameters in the web service yet. Once I added them in the web service I was able to pass without any trouble at all...
Ashish Gupta ended up mentioning this in one of the comments not too long after I finally realized this. I am embarrassed to admit this now that this one issue caused me so much trouble... and work.
Basically by doing this once the Web Reference was updated.
Dim results As Boolean = WebService.Import("something to pass", "something else")
To go back to my original question, I also ended up switching to a Windows Service and I am happy with that once I worked all my issues out. It seems to me to be the most robust option with the easiest setup/portability.
Upvotes: 1
Reputation: 11
Try using the Windows Task Scheduler, it has many, many options for scheduling, i.e. system startup, at a scheduled time, etc.
Upvotes: 1