国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁(yè) > 編程 > .NET > 正文

ASP.NET如何定時(shí)調(diào)用WebService服務(wù)

2024-07-10 13:29:26
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

在ASP.NET程序中,可以通過(guò)Time組件實(shí)現(xiàn)定時(shí)器功能,但是它與數(shù)據(jù)庫(kù)中的任務(wù)計(jì)劃不一樣,它必須基于程序正在運(yùn)行中才可生效,而數(shù)據(jù)庫(kù)任務(wù)計(jì)劃是不需要基于ASP.NET程序運(yùn)行而執(zhí)行任務(wù)。

下面是一個(gè)實(shí)際案例:

某個(gè)項(xiàng)目有一個(gè)需求,需要定時(shí)去調(diào)用別家公司的一個(gè)Web 系統(tǒng)的 WebService,把他們系統(tǒng)中的數(shù)據(jù)導(dǎo)入到我們的系統(tǒng)中。由于是調(diào)用 Web 接口,這就無(wú)法使用數(shù)據(jù)庫(kù)中的任務(wù)計(jì)劃實(shí)現(xiàn)了。后來(lái)想到使用Time 組件,利用Global 中的Application。

 

 
  1. using System;  
  2. using System.Collections;  
  3. using System.Configuration;  
  4. using System.Data;  
  5. using System.Linq;  
  6. using System.Web;  
  7. using System.Web.Security;  
  8. using System.Web.SessionState;  
  9. using System.Xml.Linq;  
  10.  
  11. namespace MyNet  
  12. {  
  13. public class Global : System.Web.HttpApplication  
  14. {  
  15.  
  16. protected void Application_Start(object sender, EventArgs e)  
  17. {  
  18. System.Timers.Timer timer1 = new System.Timers.Timer();  
  19. timer1.Interval = 30000; // 30000 毫秒 = 30秒  
  20. timer1.Elapsed += new System.Timers.ElapsedEventHandler(Time1_Elapsed);  
  21. timer1.AutoReset = true;  
  22. timer1.Enabled = true;  
  23. timer1.Start();  
  24. }  
  25.  
  26. protected void Session_Start(object sender, EventArgs e)  
  27. {  
  28.  
  29. }  
  30.  
  31. protected void Application_BeginRequest(object sender, EventArgs e)  
  32. {  
  33.  
  34. }  
  35.  
  36. protected void Application_AuthenticateRequest(object sender, EventArgs e)  
  37. {  
  38.  
  39. }  
  40.  
  41. protected void Application_Error(object sender, EventArgs e)  
  42. {  
  43.  
  44. }  
  45.  
  46. protected void Session_End(object sender, EventArgs e)  
  47. {  
  48.  
  49. }  
  50.  
  51. protected void Application_End(object sender, EventArgs e)  
  52. {  
  53.  
  54. }  
  55.  
  56. void Time1_Elapsed(object source, System.Timers.ElapsedEventArgs e)  
  57. {  
  58. localhost.MyWebService ws = new localhost.MyWebService();  
  59. ws.InsertMyWebService();  
  60. }  
  61. }  

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

以上內(nèi)容介紹了ASP.NET如何定時(shí)調(diào)用WebService服務(wù)的方法,希望對(duì)大家的學(xué)習(xí)有所幫助。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 武宣县| 渭源县| 永兴县| 河东区| 双江| 涿鹿县| 安平县| 无棣县| 苍山县| 湘潭市| 汉阴县| 日喀则市| 股票| 汉中市| 阜新市| 靖西县| 西畴县| 修文县| 类乌齐县| 宁夏| 花垣县| 肇东市| 牙克石市| 桃园县| 黔西县| 连城县| 巴马| 通许县| 紫云| 天峨县| 宁明县| 垫江县| 山东| 惠州市| 威远县| 通州市| 慈溪市| 东阳市| 东阳市| 平阴县| 梧州市|