ASP.NET如何定時(shí)調(diào)用WebService服務(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。
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();
}
}
}
備注:不會(huì)受多個(gè)用戶(hù)使用系統(tǒng)的影響,但必須最少有一個(gè)用戶(hù)在使用系統(tǒng),否則定時(shí)器程序不會(huì)執(zhí)行。
以上內(nèi)容介紹了ASP.NET如何定時(shí)調(diào)用WebService服務(wù)的方法,希望對(duì)大家的學(xué)習(xí)有所幫助。
相關(guān)文章
ASP.NET框架中的數(shù)據(jù)綁定概要與數(shù)據(jù)綁定表達(dá)式的使用
數(shù)據(jù)綁定是ASP.NET中操作數(shù)據(jù)的基礎(chǔ)方式,這里我們暫時(shí)拋開(kāi).NET提供的控件,來(lái)從基礎(chǔ)上講解ASP.NET框架中的數(shù)據(jù)綁定概要與數(shù)據(jù)綁定表達(dá)式的使用:2016-06-06
巧妙使用JQuery Clone 添加多行數(shù)據(jù),并更新到數(shù)據(jù)庫(kù)的實(shí)現(xiàn)代碼
巧妙使用JQuery Clone 添加多行數(shù)據(jù),并更新到數(shù)據(jù)庫(kù)的實(shí)現(xiàn)代碼,需要的朋友可以參考下。2011-12-12
.NET?Core利用?AsyncLocal?實(shí)現(xiàn)共享變量的代碼詳解
在Web?應(yīng)用程序中,我們經(jīng)常會(huì)遇到這樣的場(chǎng)景,如用戶(hù)信息,租戶(hù)信息本次的請(qǐng)求過(guò)程中都是固定的,我們希望是這種信息在本次請(qǐng)求內(nèi),一次賦值,到處使用。本文就來(lái)探討一下,如何在.NET?Core?下去利用AsyncLocal?實(shí)現(xiàn)全局共享變量2022-04-04
Datatable刪除行的Delete和Remove方法的區(qū)別介紹
Datatable刪除行的Delete和Remove方法的區(qū)別介紹,需要的朋友可以參考一下2013-03-03
CommunityServer又稱(chēng)CS論壇的相關(guān)學(xué)習(xí)資料
以前項(xiàng)目需要整合這個(gè)論壇,同事找了一些資料,現(xiàn)在放上來(lái),并說(shuō)下自己對(duì)這個(gè)論壇的看法。2009-05-05
Asp.net動(dòng)態(tài)生成html頁(yè)面的方法分享
這篇文章介紹了Asp.net動(dòng)態(tài)生成html頁(yè)面的方法,有需要的朋友可以參考一下2013-10-10

