在WebService中使用Timer事件

在WebService开发时,有时需要做轮询操作,可以使用Timer ,注意是System.Timers.Timer,且事件的触发必须是经过一次WebService调用后。

using  System;
using  System.Web;
using  System.Web.Services;
using  System.Web.Services.Protocols;

using  System.IO;

[WebService(Namespace 
=   " http://tempuri.org/ " )]
[WebServiceBinding(ConformsTo 
=  WsiProfiles.BasicProfile1_1)]
public   class  Service : System.Web.Services.WebService
{
    
public  Service () {

        
// 如果使用设计的组件,请取消注释以下行 
        InitializeComponent(); 
    }

    
private  System.Timers.Timer timer1;
    
private  System.ComponentModel.IContainer components;

    
private   void  InitializeComponent()
    {
        
this .components  =   new  System.ComponentModel.Container();
        
this .timer1  =   new  System.Timers.Timer();
        
//  
        
//  timer1
        
//  
         this .timer1.Enabled  =   true ;
        
this .timer1.Interval  =   1000 ;
        
this .timer1.Elapsed  +=   new  System.Timers.ElapsedEventHandler(timer1_Elapsed);
    }

    
private   void  timer1_Elapsed( object  sender, System.Timers.ElapsedEventArgs e)
    {
        
using  (StreamWriter sw  =   new  StreamWriter(Server.MapPath( " . " ) + " /TextFile.txt " ))
        {
            sw.WriteLine(DateTime.Now);
        }
    }

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
使用Spring Boot启动WebService时,您可能会遇到一些问题。根据引用的错误信息,您的实现类"com.hy.springboot.webservice.demo.service.impl.MyServiceImpl"没有添加"@WebService"或"@WebServiceProvider"注解。这些注解是必需的,以便Spring Boot能够正确地识别和配置您的WebService服务。 根据引用,在使用Spring Boot创建WebService时,您需要添加相应的WebService依赖。您可以在pom.xml文件添加以下依赖项: ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web-services</artifactId> </dependency> ``` 根据引用提供的示例,您还需要确保您的Application类上添加了"@RestController"和"@SpringBootApplication"注解,并且在该类注入了Endpoint bean。此外,您可以添加一个用于测试Endpoint的RequestMapping方法。 如果您遵循了以上步骤,但仍然无法启动WebService,请确保您的项目结构和配置正确,并检查是否有其他错误或异常。另外,您可以查看日志文件以获取更多详细的错误信息,以帮助您定位问题所在。 希望以上信息对您有所帮助,祝您成功启动Spring BootWebService!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [SpringBoot使用WebService(简单的使用)](https://blog.csdn.net/weixin_45492007/article/details/99638002)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值