By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,572 Members | 1,439 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,572 IT Pros & Developers. It's quick & easy.

Web service with timer

P: 2
Hi Bytes Crew,
I was told to do a web service with a timer. The timer has to be executed every 30 seconds to get information from a Database. So, when a user makes a request to the web service, the information has to be provided by a dataset and no from the Database. Is there any example of a web service with timer? I just created the web service but no sure how to add a timer and makes it works.
any help is really appreaciated.
Oct 2 '12 #1
Share this Question
Share on Google+
3 Replies

Expert Mod 5K+
P: 5,397
see if any of this tickles your fancy
Oct 3 '12 #2

P: 2
Hi zmbd, I looked up at the info you sent and I did this, can you let me know if Im in the right track, please? Here is my web service with the timer:
Expand|Select|Wrap|Line Numbers
  1. Imports System.Web.Services
  2. Imports System.Web.Services.Protocols
  3. Imports System.ComponentModel
  4. Imports System.Timers
  6. ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
  7. ' <System.Web.Script.Services.ScriptService()> _
  8. <System.Web.Services.WebService(Namespace:="")> _
  9. <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
  10. <ToolboxItem(False)> _
  11. Public Class WebService1
  12.     Inherits System.Web.Services.WebService
  14.     Shared ds As DataSet = New DataSet()
  15.     Private Shared tmrGetPending As Timer
  17.     Shared Sub New()
  18.         tmrGetPending.Start()
  19.         tmrGetPending.Interval = 5000
  20.         AddHandler tmrGetPending.Elapsed, AddressOf tmrGetPending_Elapsed
  21.     End Sub
  23.     Private Shared Sub tmrGetPending_Elapsed(ByVal sender As Object, ByVal e As EventArgs)
  24.         ds = GetData()
  25.     End Sub
  27.     <WebMethod()> _
  28.     Public Function GetPending() As DataSet
  29.         Return ds
  30.     End Function
  32.     Public Shared Function GetData() As DataSet
  33.         'Dim connStr As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
  34.         Return ds
  35.     End Function
  36. End Class
With the interval option set to 5000, it means that the timer will be fired every time 5000 automatically?
The function GetData is the one that will be getting the info from the database.
the sub tmrgetpending_elapsed will be fired every 5000 as set in the interval?
the function getpending is the one used to call from the client.
I have a sub new that set the timer and interval.
Oct 3 '12 #3

Expert Mod 5K+
P: 5,397
I'm still fairly new to .net stuff so hopefully one of the more knowledgable will be able to double check things for you.
Oct 3 '12 #4

Post your reply

Sign in to post your reply or Sign up for a free account.