This is a quick post on a method that explains how to invoke Asp.Net Web Service(s) periodically. It is inevitable, that once in a while there will be a requirement where you will be pushing / pulling data via Asp.Net Web Services periodically. As much this is a common requirement, however there are several ways in which it can be engineered.
In the code below, I have used a Asp:Timer object to fire a desired web service periodically (every 1 minute or 60 seconds or 60,000 milliseconds). I don’t claim this is innovative way of doing this. Needless to say, this could be just one of the ways in which such a requirement can be achieved.
Declare your Asp:Timer control; requires a ScriptManager Control to work
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:Timer ID="WebSvcPeriodInvoke" runat="server" Interval="60000"></asp:Timer>
Declare the native Tick() method for Asp.Timer; code-behind
Protected Sub WebSvcPeriodInvoke_Tick(sender As Object, e As System.EventArgs) Handles WebSvcPeriodInvoke.Tick ' Invoke WebService Programmatically Dim WebSvcObj As NameOfWebService = New NameOfWebService Dim _MethodCall As int = WebSvcObj.NameOfYourMethod(Arg1, Arg2) ' Do Something with _MethodCall Variable End Sub
Using the method above, your .aspx page is now using a Asp:Timer control to invoke an Asp.Net Web Service periodically after every 1 minute. This is super handy, you can easily pass in parameters if required to Web Service and play with the result or be imaginative where required.