I have a couple of queries for a web site that take a long time to run due to the data model and the amount of data held in the tables. So far I've been running them manually against the database to avoid any timeout issues etc.. however the site owner has asked for these to be made available on the site so he can get the query results.
由于数据模型和表中保存的数据量,我对网站有几个查询需要很长时间才能运行。到目前为止,我一直在针对数据库手动运行它们以避免任何超时问题等。但是网站所有者要求在网站上提供这些以便他可以获得查询结果。
I had thought of doing this via a .NET web service and having the classic ASP page call this asynchronously. The web page would just initiate the process and before redirecting the user to another screen. The web service would then run the query and email the user the results in a CSV.
我曾经想过通过.NET Web服务这样做,并让经典的ASP页面异步调用它。网页将启动该过程,然后再将用户重定向到另一个屏幕。然后,Web服务将运行查询并以CSV格式向用户发送结果。
However, I can't seem to get this to work. The service runs ok if I invoke it through the screen in IE but calling it through an Ajax call in ASP seems to be an issue - no error is generated but neither is the CSV file created.
但是,我似乎无法让这个工作。如果我通过IE中的屏幕调用它但是通过ASP中的Ajax调用调用它似乎是一个问题 - 该服务运行正常 - 没有生成错误但是CSV文件也没有创建。
I've enclosed the classic ASP code below. The service only has one method with a parameter of the name email which is of the type string. Can anyone see anything wrong with it? Also, this the best way to be doing this or should I be thinking of another approach?
我在下面附上了经典的ASP代码。该服务只有一个方法,其名称为email的参数,其类型为字符串。任何人都可以看到它有什么问题吗?此外,这是最好的方式,或者我应该考虑另一种方法?
Thanks in advance,
提前致谢,
Phil
菲尔
CODE
码
<%
message = "http://wwww.example.com/service/query.asmx/GetResults?email=test"
set req = server.createobject("MSXML2.XMLHTTP")
With req
.open "GET", message, False
.setRequestHeader "Content-Type", "text/xml"
.send
End With
works = req.responseText
response.redirect "http://www.bbc.co.uk"
%>
2 个解决方案
#1
3
The idea of asynchronously requesting the work and arranging for its later delivery seems very reasonable to me. I don't speak ASP well enough to know what's wring with your attempt, but is that really an asnch call you have there? Would the seb service also suffer from an HTTP connection timeout?
异步请求工作并安排其后期交付的想法对我来说似乎非常合理。我不会说ASP太好,不知道你的尝试会弄什么,但那真的是你在那里的一个白话吗? seb服务是否也会受到HTTP连接超时的影响?
My approach would have been for an Ajax request to place a request on a queue and return, no need for a redirect, you're still on the page where the user makes teh request, your java script could just acknowledge that the requests was sent. Alterntively, your more traditional "submit a page, stash the request, display another page" appraoch can work, but the the stashing is just to put the request on a queue.
我的方法是将Ajax请求放在队列上并返回,不需要重定向,你仍然在用户发出请求的页面上,你的java脚本只能确认请求已被发送。或者,您更传统的“提交页面,存储请求,显示另一个页面”appraoch可以工作,但存储只是将请求放在队列中。
An advantage of the queueing approach is that by controlling the number of daemons we can get controlled parallelism in servicing the requests - avoid overloading the DB. Also the queues can persist and allow a leisurely delivery of the responses.
排队方法的一个优点是通过控制守护进程的数量,我们可以在服务请求时获得受控制的并行性 - 避免数据库过载。队列也可以持续存在并允许悠闲地传递响应。
I assume that MS queues then let you have a daemon processing the reuquest and delivering the responses. Clearly email works, but strikes me as a tad unfriendly. With Ajax style interfaces it would be quite easy to invisibly poll for the status of requests and obtain the results when they are ready, or even to use Comet-style push delivery of the responses.
我假设MS队列然后让你有一个守护进程处理reuquest并传递响应。显然电子邮件是有效的,但让我觉得有点不友好。使用Ajax样式接口,可以很容易地无形地轮询请求的状态并在准备好后获得结果,甚至可以使用Comet风格的推送传递响应。
#2
1
The problem here, as djna noted, is that you are not calling a callback function. Due to the asynchronously aspect of Ajax, you have set up a callback function that will be executed when the Ajax call ends.
正如djna所指出的,这里的问题是你没有调用回调函数。由于Ajax的异步方面,您已经设置了一个回调函数,该函数将在Ajax调用结束时执行。
Long story short:
Call the webservice from a javascript function, preferably using JQuery to avoid cross browser incompatibilities
简而言之:从javascript函数调用webservice,最好使用JQuery来避免跨浏览器的不兼容性
Code:
码:
<div id="results">Processing query. Please wait</div>
<script type="text/javascript">
$(document).ready(function(){
$("#results").load("http://wwww.mywebsite.com/service/query.asmx/GetResults?email=test&Rnd=" + Math.random().toString());
});
</script>
#1
3
The idea of asynchronously requesting the work and arranging for its later delivery seems very reasonable to me. I don't speak ASP well enough to know what's wring with your attempt, but is that really an asnch call you have there? Would the seb service also suffer from an HTTP connection timeout?
异步请求工作并安排其后期交付的想法对我来说似乎非常合理。我不会说ASP太好,不知道你的尝试会弄什么,但那真的是你在那里的一个白话吗? seb服务是否也会受到HTTP连接超时的影响?
My approach would have been for an Ajax request to place a request on a queue and return, no need for a redirect, you're still on the page where the user makes teh request, your java script could just acknowledge that the requests was sent. Alterntively, your more traditional "submit a page, stash the request, display another page" appraoch can work, but the the stashing is just to put the request on a queue.
我的方法是将Ajax请求放在队列上并返回,不需要重定向,你仍然在用户发出请求的页面上,你的java脚本只能确认请求已被发送。或者,您更传统的“提交页面,存储请求,显示另一个页面”appraoch可以工作,但存储只是将请求放在队列中。
An advantage of the queueing approach is that by controlling the number of daemons we can get controlled parallelism in servicing the requests - avoid overloading the DB. Also the queues can persist and allow a leisurely delivery of the responses.
排队方法的一个优点是通过控制守护进程的数量,我们可以在服务请求时获得受控制的并行性 - 避免数据库过载。队列也可以持续存在并允许悠闲地传递响应。
I assume that MS queues then let you have a daemon processing the reuquest and delivering the responses. Clearly email works, but strikes me as a tad unfriendly. With Ajax style interfaces it would be quite easy to invisibly poll for the status of requests and obtain the results when they are ready, or even to use Comet-style push delivery of the responses.
我假设MS队列然后让你有一个守护进程处理reuquest并传递响应。显然电子邮件是有效的,但让我觉得有点不友好。使用Ajax样式接口,可以很容易地无形地轮询请求的状态并在准备好后获得结果,甚至可以使用Comet风格的推送传递响应。
#2
1
The problem here, as djna noted, is that you are not calling a callback function. Due to the asynchronously aspect of Ajax, you have set up a callback function that will be executed when the Ajax call ends.
正如djna所指出的,这里的问题是你没有调用回调函数。由于Ajax的异步方面,您已经设置了一个回调函数,该函数将在Ajax调用结束时执行。
Long story short:
Call the webservice from a javascript function, preferably using JQuery to avoid cross browser incompatibilities
简而言之:从javascript函数调用webservice,最好使用JQuery来避免跨浏览器的不兼容性
Code:
码:
<div id="results">Processing query. Please wait</div>
<script type="text/javascript">
$(document).ready(function(){
$("#results").load("http://wwww.mywebsite.com/service/query.asmx/GetResults?email=test&Rnd=" + Math.random().toString());
});
</script>