ASP.NET如何定時調用WebService服務_實用技巧

來源:互聯網
上載者:User

下面是一個實際案例:

某個項目有一個需求,需要定時去調用別家公司的一個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服務的方法,希望對大家的學習有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.