最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

ASP.NET如何定時調用WebService服務

 更新時間:2015年10月09日 11:02:15   投稿:lijiao  
在ASP.NET程序中,可以通過Time組件實現(xiàn)定時器功能,但是它與數(shù)據(jù)庫中的任務計劃不一樣,它必須基于程序正在運行中才可生效,而數(shù)據(jù)庫任務計劃是不需要基于ASP.NET程序運行而執(zhí)行任務。

下面是一個實際案例:

某個項目有一個需求,需要定時去調用別家公司的一個Web 系統(tǒng)的 WebService,把他們系統(tǒng)中的數(shù)據(jù)導入到我們的系統(tǒng)中。由于是調用 Web 接口,這就無法使用數(shù)據(jù)庫中的任務計劃實現(xiàn)了。后來想到使用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(); 
  } 
 } 
}

備注:不會受多個用戶使用系統(tǒng)的影響,但必須最少有一個用戶在使用系統(tǒng),否則定時器程序不會執(zhí)行。

以上內(nèi)容介紹了ASP.NET如何定時調用WebService服務的方法,希望對大家的學習有所幫助。

相關文章

最新評論

义马市| 磐石市| 綦江县| 大悟县| 南汇区| 安西县| 潢川县| 揭阳市| 武平县| 江都市| 甘谷县| 金山区| 外汇| 芦溪县| 澄江县| 延庆县| 五大连池市| 浑源县| 陇南市| 河池市| 九龙坡区| 中西区| 顺平县| 牡丹江市| 宣威市| 塔河县| 海南省| 桓台县| 婺源县| 昭觉县| 莒南县| 轮台县| 江孜县| 厦门市| 沅江市| 乌拉特前旗| 和平县| 泰兴市| 石林| 建昌县| 菏泽市|