ASP.NET如何定時調用WebService服務
下面是一個實際案例:
某個項目有一個需求,需要定時去調用別家公司的一個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í)行。
以上內容介紹了ASP.NET如何定時調用WebService服務的方法,希望對大家的學習有所幫助。
相關文章
.NET中用ICSharpCode.TextEditor自定義代碼折疊與高亮
這篇文章主要給大家介紹了.NET中用ICSharpCode.TextEditor自定義代碼折疊與高亮的相關資料,文中通過示例代碼與圖片介紹的很詳細,需要的朋友可以參考借鑒,下面來一起看看吧。2017-02-02ASP.NET Gridview與checkbox全選、全不選實現(xiàn)代碼
ASP.NET Gridview checkbox全選與全不選實現(xiàn)代碼,其實原理就是利用js來實現(xiàn)的,但需要簡單的設置下回傳。2010-04-04.net 運用二進制位運算進行數(shù)據(jù)庫權限管理
.net 運用二進制位運算進行數(shù)據(jù)庫權限管理 ,需要的朋友可以參考一下2013-02-02MVC4制作網(wǎng)站教程第三章 瀏覽用戶組操作3.1
這篇文章主要為大家詳細介紹了MVC4制作網(wǎng)站教程,瀏覽用戶組功能的實現(xiàn)代碼,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-08-08