您如何衡量 Web 服务调用的进度? [英] How do you measure the progress of a web service call?

查看:31
本文介绍了您如何衡量 Web 服务调用的进度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ASP.NET web 服务,它做了一些繁重的工作,比如一些文件操作,或者从一堆水晶报表中生成 Excel 表格.我不想被调用这个 web 服务阻止,所以我想让 web 服务调用异步.此外,我想从网页调用此 Web 服务,并且需要某种机制来允许我继续轮询服务器,以便我可以在屏幕上显示一些进度指示器,例如,已经处理.请注意,我不想要 Web 方法调用完成时的通知,而是想要实时进度状态.我该怎么做?

I have an ASP.NET web service which does some heavy lifting, like say,some file operations, or generating Excel Sheets from a bunch of crystal reports. I don't want to be blocked by calling this web service, so i want to make the web service call asynchronous. Also, I want to call this web service from a web page, and want some mechanism which will allow me to keep polling the server so that i can i can show some indicator of progress on the screen, like say, the number of files that have been processed. Please note that i do not want a notification on completion of the web method call, rather, i want a live progress status. How do i go about it?

推荐答案

在服务器上编写一个单独的方法,您可以通过传递已调度的作业的 ID 进行查询,该方法返回 0-100 (或 0.0 和 1.0,或其他)它有多远.

Write a separate method on the server that you can query by passing the ID of the job that has been scheduled and which returns an approximate value between 0-100 (or 0.0 and 1.0, or whatever) of how far along it is.

例如在 REST 风格中,您可以向 http://yourserver.com/app/jobstatus/4133/ 发出 GET 请求,这将返回一个简单的52"作为 text/plain.然后你只需要每隔(秒?两秒?十秒?)查询一次,看看它有多远.

E.g. in REST-style, you could make a GET request to http://yourserver.com/app/jobstatus/4133/ which would return a simple '52' as text/plain. Then you just have to query that every (second? two seconds? ten seconds?) to see how far along it is.

您实际如何在后端完成监控在很大程度上取决于您的流程是什么以及它是如何工作的.

How you actually accomplish the monitoring on the backend hugely depends on what your process is and how it works.

这篇关于您如何衡量 Web 服务调用的进度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆