Web service with timer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jmclean22
    New Member
    • Oct 2012
    • 2

    Web service with timer

    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.
    JM
  • zmbd
    Recognized Expert Moderator Expert
    • Mar 2012
    • 5501

    #2
    see if any of this tickles your fancy
    Performs asynchronous or synchronous Web page postbacks at a defined interval.

    Comment

    • jmclean22
      New Member
      • Oct 2012
      • 2

      #3
      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:
      Code:
      Imports System.Web.Services
      Imports System.Web.Services.Protocols
      Imports System.ComponentModel
      Imports System.Timers
      
      ' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
      ' <System.Web.Script.Services.ScriptService()> _
      <System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
      <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
      <ToolboxItem(False)> _
      Public Class WebService1
          Inherits System.Web.Services.WebService
      
          Shared ds As DataSet = New DataSet()
          Private Shared tmrGetPending As Timer
      
          Shared Sub New()
              tmrGetPending.Start()
              tmrGetPending.Interval = 5000
              AddHandler tmrGetPending.Elapsed, AddressOf tmrGetPending_Elapsed
          End Sub
      
          Private Shared Sub tmrGetPending_Elapsed(ByVal sender As Object, ByVal e As EventArgs)
              ds = GetData()
          End Sub
      
          <WebMethod()> _
          Public Function GetPending() As DataSet
              Return ds
          End Function
      
          Public Shared Function GetData() As DataSet
              'Dim connStr As String = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
              Return ds
          End Function
      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_e lapsed 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.

      Comment

      • zmbd
        Recognized Expert Moderator Expert
        • Mar 2012
        • 5501

        #4
        I'm still fairly new to .net stuff so hopefully one of the more knowledgable will be able to double check things for you.

        Comment

        Working...