当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.NET如何定时调用WebService服务

ASP.NET如何定时调用WebService服务

2017年12月12日  | 移动技术网IT编程  | 我要评论
下面是一个实际案例: 某个项目有一个需求,需要定时去调用别家公司的一个web 系统的 webservice,把他们系统中的数据导入到我们的系统中。由于是调用 web 接口

下面是一个实际案例:

某个项目有一个需求,需要定时去调用别家公司的一个web 系统的 webservice,把他们系统中的数据导入到我们的系统中。由于是调用 web 接口,这就无法使用数据库中的任务计划实现了。后来想到使用time 组件,利用global 中的application。

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 毫秒 = 30秒 
   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(); 
  } 
 } 
}

备注:不会受多个用户使用系统的影响,但必须最少有一个用户在使用系统,否则定时器程序不会执行。

以上内容介绍了asp.net如何定时调用webservice服务的方法,希望对大家的学习有所帮助。

如您对本文有疑问或者有任何想说的,请点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网