0

这是我的模拟过程:Web 服务 FindPrimeNumbers(int Num) 将找到多个等于输入值的素数。例如,如果 (Num = 1000),那么 FindPrimeNumber(1000) 将找到以 1、2、3 等开头的前 1000 个素数。每当找到素数时,它应该通过将新的素数附加到一个标签。

我正在考虑使用 .net web api 作为我的服务。我不知道的是如何(引发事件?)在找到素数时更新网页。

谢谢您的帮助。

4

2 回答 2

0

ajax wouldn't work here - it's either success or error. Think about it this way - if your web service was returning json and you flushed a partial response, it would end up looking like {'test': 'fun; it would be unparsable and of no use.

You'd need to use a WebSocket instead as LB mentioned. This will allow you to open a connection and raise events on the server and client side between the two as you please. Here's a link with browsers that support. (currently Chrome/FF/Safari/IE10+)

于 2013-10-15T21:52:40.060 回答
0

我以前也想过这样的事情,但我仍然没有机会真正去研究它。我的建议是看看SignalR。不知何故,您将在后面的代码中执行一个长期运行的函数。然后每次有新结果时它都会运行并更新客户端,直到完成。

于 2013-10-15T22:04:03.983 回答