To make the progress report process a little more reliable and separate it from the request / response, I perform the processing in the Windows service and save the intended response to the file. When the client starts polling for updates, it is assumed that the controller returns the contents of the file, regardless of what they are, like a JSON string.
The contents of the file are pre-serialized in JSON. This should ensure that there is nothing in the way of the answer. No processing should happen (without reading the contents of the file in a line and returning it) to get an answer.
I originally, although it would be quite simple, but it is not.
Currently, my controller method is as follows:
Controller
Update
[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); }
And Fiddler returns this as a raw answer
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\":[]}"
Ajax
Update
Further, most likely, it will be changed later, but for now it works when I generate a response class and return it as JSON, as an ordinary person.
this.CheckForUpdate = function () { var parent = this; if (this.BatchSearchId != null && WorkflowState.SelectedSearchList != "") { showAjaxLoader = false; if (progressPending != true) { progressPending = true; $.ajax({ url: WorkflowState.UpdateBatchLink + "?SearchListID=" + WorkflowState.SelectedSearchList, type: 'POST', contentType: 'application/json; charset=utf-8', cache: false, success: function (data) { for (var i = 0; i < data.MemberStatuses.length; i++) { var response = data.MemberStatuses[i]; parent.UpdateCellStatus(response); } if (data.StopPolling = true) { parent.StopPullingForUpdates(); } showAjaxLoader = true; } }); progressPending = false; } }
json asp.net-mvc
CodeWarrior Mar 19 '12 at 20:50 2012-03-19 20:50
source share