为了使进度报告过程更可靠并将其与请求/响应分离,我正在Windows服务中执行处理并将预期的响应持久保存到文件中.当客户端开始轮询更新时,意图是控制器将文件的内容(无论它们是什么)作为JSON字符串返回.
该文件的内容已预先序列化为JSON.这是为了确保没有任何阻碍响应的方式.不需要处理(没有将文件内容读入字符串并返回它)以获得响应.
我最初虽然这很简单,但事实并非如此.
目前我的控制器方法看起来如此:
[HttpPost]
public JsonResult UpdateBatchSearchMembers()
{
string path = Properties.Settings.Default.ResponsePath;
string returntext;
if (!System.IO.File.Exists(path))
returntext = Properties.Settings.Default.EmptyBatchSearchUpdate;
else
returntext = System.IO.File.ReadAllText(path);
return this.Json(returntext);
}
Run Code Online (Sandbox Code Playgroud)
Fiddler将此作为原始回复
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Mon, 19 Mar 2012 20:30:05 GMT
X-AspNet-Version: 4.0.30319
X-AspNetMvc-Version: 3.0
Cache-Control: private
Content-Type: application/json; charset=utf-8
Content-Length: 81
Connection: Close
"{\"StopPolling\":false,\"BatchSearchProgressReports\":[],\"MemberStatuses\":[]}"
Run Code Online (Sandbox Code Playgroud)
以下内容可能会在以后更改,但是现在,当我生成响应类并将其作为JSON返回时,这就像普通人一样.
this.CheckForUpdate = function () {
var parent = this;
if (this.BatchSearchId != null && WorkflowState.SelectedSearchList != "") {
showAjaxLoader …Run Code Online (Sandbox Code Playgroud)