ASP. How does NET call WebService service regularly

  • 2021-07-02 23:56:49
  • OfStack

The following is a practical case:

There is a requirement in a project, which needs to call WebService of an Web system of other companies regularly to import the data in their systems into our system. Because the Web interface is called, this cannot be achieved using the task schedule in the database. Later, I thought of using Time component and using Application in Global.


using System; 
using System.Collections; 
using System.Configuration; 
using System.Data; 
using System.Linq; 
using System.Web; 
using System.Web.Security; 
using System.Web.SessionState; 
using System.Xml.Linq; 
  
namespace MyNet 
{ 
 public class Global : System.Web.HttpApplication 
 { 
  
  protected void Application_Start(object sender, EventArgs e) 
  { 
   System.Timers.Timer timer1 = new System.Timers.Timer(); 
   timer1.Interval = 30000; // 30000  Milliseconds  = 30 Seconds  
   timer1.Elapsed += new System.Timers.ElapsedEventHandler(Time1_Elapsed); 
   timer1.AutoReset = true; 
   timer1.Enabled = true; 
   timer1.Start(); 
  } 
  
  protected void Session_Start(object sender, EventArgs e) 
  { 
  
  } 
  
  protected void Application_BeginRequest(object sender, EventArgs e) 
  { 
  
  } 
  
  protected void Application_AuthenticateRequest(object sender, EventArgs e) 
  { 
  
  } 
  
  protected void Application_Error(object sender, EventArgs e) 
  { 
  
  } 
  
  protected void Session_End(object sender, EventArgs e) 
  { 
  
  } 
  
  protected void Application_End(object sender, EventArgs e) 
  { 
  
  } 
  
  void Time1_Elapsed(object source, System.Timers.ElapsedEventArgs e) 
  { 
   localhost.MyWebService ws = new localhost.MyWebService(); 
   ws.InsertMyWebService(); 
  } 
 } 
}

Note: It will not be affected by multiple users using the system, but at least one user must be using the system, otherwise the timer program will not execute.

The above content introduces the method of how ASP. NET calls WebService service regularly, hoping to help everyone's study.


Related articles: