如何序列化 .net Web 服务的处理?
我计划使用 .net Web 服务来批处理数据库记录。 Web 服务请求来自 SQL Server 存储过程,该过程由 SQL Server 代理每分钟调用一次。我只想一次运行一批,因为这里的重点是避免服务器过载。
是否有一种好的方法可以序列化请求,或者如果已经有请求正在处理,则可以拒绝请求?
我正在考虑让一个 Web 服务实例将一个标志写入数据库,以便后续的 Web 服务实例在启动时可以读取该标志。如果它已经设置,那么 Web 服务将返回而不执行任何操作。安全措施可能是,如果自设置标志以来已经过了十分钟,那么设置该标志的 Web 服务实例将被视为失败。
有什么想法吗?
干杯,伊恩。
I'm planning on using a .net web service to batch process database records. The web service requests are coming in from a SQL Server stored procedure that's called by SQL Server Agent every minute. I only want one batch to be running at a time because the whole point here is to avoid over loading the server.
Is there a good way of serializing the requests or maybe rejecting requests if there's already one in progress?
I was thinking of having a web service instance write a flag into the database that subsequent web service instances can read when they start up. If its already set then a web service will return without doing anything. A safe guard could be that if its been ten minutes, say, since the flag was set then the web service instance that set the flag would be considered to have failed.
Any thoughts?
Cheers, Ian.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 Web 服务上的静态属性来设置它何时运行,其他实例将检查它(在适当的锁定之后)并正常失败(如果是这样)。这也可以考虑到你的超时时间。
但有没有更简单的方法来做到这一点呢?您似乎正在谈论从数据库到 Web 服务,然后再次返回数据库,以及您想要每分钟运行的东西。事情似乎不太对劲。您是否有无法使用 Windows 服务甚至 Windows 任务计划程序的原因?
You could use a static property on the web service to set when it's running, and other instances would check it (after appropriate locking) and fail gracefully, if so. That could take into account your time out, as well.
But is there not an easier way to do this? You seem to be talking about going back and forth from database to web service and back to database again, and for something you want running every minute. Something does not seem quite right. Is there a reason you can't use a Windows service, or even the Windows Task Scheduler?