如何从Web服务获取通知到ASP.NET MVC视图

任务:

  • 将一些数据添加到数据库 – 大约5分钟
  • 向客户端发送通知“添加到数据库的数据”
  • 过程数据 – 大约15分钟
  • 向客户发送通知“数据已处理”

在代码中:

ASMX Web服务

[SoapDocumentMethod(OneWay = true)] [WebMethod] public void AddAndProcess(DataSet _DataToProcess) { //inserts data to DB SendNotification("Data added to database"); ProcessData(_DataToProcess); } [SoapDocumentMethod(OneWay = true)] [WebMethod] public void ProcessData(DataSet _DataToProcess) { //Process data SendNotification("The data is processed"); } public void SendNotification(string NotificationMessage) { //do something to send a notification to client } 

ASP.NET MVC视图

 @using (Html.BeginForm("AddAndProcess", "DataProcessor", FormMethod.Post, new {@class = "form-horizontal", role = "form", enctype = "multipart/form-data" })) { @Html.AntiForgeryToken() 

Upload data file

@Html.Label("Select data file", new { @class = "col-md-4 control-label" }) @Html.TextBox("file", null, new { type = "file" })
@Html.TextBox("Submit", "Process", new { type = "submit" })
}

数据处理器控制器

 public class DataProcessor : Controller { public ActionResult AddAndProcess() { //Call data processor web services to //1. Add some data to database - approx 5 minutes //2. Send a notification to client "Data added to database" //3. Process data - approx 15 minutes //4. Send a notification to client "The data is processed" return View(); } } 

描述:

我有一个ASP.NET MVC视图,我需要在其上显示如上所示的函数执行状态通知。

为了节省用户的时间,Web服务标记为SoapDocumentMethod(OneWay = true) 。 在这种情况下,我无法返回NotificationMessage字符串并在视图上显示。

问题:

如何从ASMX Web服务向ASP.NET MVC视图发送通知?