ASP.NET如何定时调用WebService服务
下面是一个实际案例:
某个项目有一个需求,需要定时去调用别家公司的一个Web系统的WebService,把他们系统中的数据导入到我们的系统中。由于是调用Web接口,这就无法使用数据库中的任务计划实现了。后来想到使用Time组件,利用Global中的Application。
usingSystem;
usingSystem.Collections;
usingSystem.Configuration;
usingSystem.Data;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.Security;
usingSystem.Web.SessionState;
usingSystem.Xml.Linq;
namespaceMyNet
{
publicclassGlobal:System.Web.HttpApplication
{
protectedvoidApplication_Start(objectsender,EventArgse)
{
System.Timers.Timertimer1=newSystem.Timers.Timer();
timer1.Interval=30000;//30000毫秒=30秒
timer1.Elapsed+=newSystem.Timers.ElapsedEventHandler(Time1_Elapsed);
timer1.AutoReset=true;
timer1.Enabled=true;
timer1.Start();
}
protectedvoidSession_Start(objectsender,EventArgse)
{
}
protectedvoidApplication_BeginRequest(objectsender,EventArgse)
{
}
protectedvoidApplication_AuthenticateRequest(objectsender,EventArgse)
{
}
protectedvoidApplication_Error(objectsender,EventArgse)
{
}
protectedvoidSession_End(objectsender,EventArgse)
{
}
protectedvoidApplication_End(objectsender,EventArgse)
{
}
voidTime1_Elapsed(objectsource,System.Timers.ElapsedEventArgse)
{
localhost.MyWebServicews=newlocalhost.MyWebService();
ws.InsertMyWebService();
}
}
}
备注:不会受多个用户使用系统的影响,但必须最少有一个用户在使用系统,否则定时器程序不会执行。
以上内容介绍了ASP.NET如何定时调用WebService服务的方法,希望对大家的学习有所帮助。
热门推荐
10 对女友的简短祝福语
11 爸爸爱你祝福语大全简短
12 婚庆花篮祝福语简短大气
13 宝子生日祝福语简短
14 带清的简短祝福语
15 学生开心成语祝福语简短
16 宝宝生日祝福语大全简短
17 英文祝福语简短带名字
18 妈妈祝福语简短16字