ASP.NET如何定時調(diào)用WebService服務(wù)
下面是一個實際案例:
某個項目有一個需求,需要定時去調(diào)用別家公司的一個Web 系統(tǒng)的 WebService,把他們系統(tǒng)中的數(shù)據(jù)導(dǎo)入到我們的系統(tǒng)中。由于是調(diào)用 Web 接口,這就無法使用數(shù)據(jù)庫中的任務(wù)計劃實現(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如何定時調(diào)用WebService服務(wù)的方法,希望對大家的學(xué)習(xí)有所幫助。
相關(guān)文章
詳解c# .net core 下的網(wǎng)絡(luò)請求
本篇文章主要介紹了詳解c# .net core 下的網(wǎng)絡(luò)請求,大致介紹下在.net core 下如何進行http請求,主要仍然是GET和POST方法,有興趣的可以了解下2017-05-05.NET中用ICSharpCode.TextEditor自定義代碼折疊與高亮
這篇文章主要給大家介紹了.NET中用ICSharpCode.TextEditor自定義代碼折疊與高亮的相關(guān)資料,文中通過示例代碼與圖片介紹的很詳細,需要的朋友可以參考借鑒,下面來一起看看吧。2017-02-02ASP.NET Gridview與checkbox全選、全不選實現(xiàn)代碼
ASP.NET Gridview checkbox全選與全不選實現(xiàn)代碼,其實原理就是利用js來實現(xiàn)的,但需要簡單的設(shè)置下回傳。2010-04-04.net 運用二進制位運算進行數(shù)據(jù)庫權(quán)限管理
.net 運用二進制位運算進行數(shù)據(jù)庫權(quán)限管理 ,需要的朋友可以參考一下2013-02-02MVC4制作網(wǎng)站教程第三章 瀏覽用戶組操作3.1
這篇文章主要為大家詳細介紹了MVC4制作網(wǎng)站教程,瀏覽用戶組功能的實現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-08-08.NET使用StackTrace獲取方法調(diào)用信息的代碼演示
StackTrace, 位于 System.Diagnostics 命名空間下,名字很直觀,它代表一個方法調(diào)用的跟蹤堆棧,里面存放著按順序排列的棧幀對象(StackFrame),每當(dāng)發(fā)生一次調(diào)用,就會壓入一個棧幀,這篇文章主要介紹了.NET使用StackTrace獲取方法調(diào)用信息,需要的朋友可以參考下2022-09-09作業(yè)調(diào)度框架Quartz.net用法詳解
本文詳細講解了作業(yè)調(diào)度框架Quartz.net的用法,文中通過示例代碼介紹的非常詳細。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-06-06HttpRequest Get和Post調(diào)用其他頁面的方法
HttpRequest Get和Post調(diào)用其他頁面的方法,需要的朋友可以參考一下2013-03-03