How to get notification from web service to ASP.NE

2019-01-20 18:34发布

Task:

  • Add some data to database - approx 5 minutes
  • Send a notification to client "Data added to database"
  • Process data - approx 15 minutes
  • Send a notification to client "The data is processed"

In code:

ASMX web services

[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 View

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

<h1>Upload data file</h1>

    <div class="form-group">
        <div class="col-md-10">
            @Html.Label("Select data file", new { @class = "col-md-4 control-label" })
            @Html.TextBox("file", null, new { type = "file" })
        </div>
    </div>

    <div class="form-group">
        <div class="col-md-offset-2 col-md-10">
            @Html.TextBox("Submit", "Process", new { type = "submit" })
        </div>
    </div>
    }

Data processor controller

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();
    }
}

Description:

I have an ASP.NET MVC view on which I need to show function execution status notification as shown above.

To save our user's time, the web services are marked SoapDocumentMethod(OneWay = true). In this case I cannot return a NotificationMessage string and show on view.

Problem:

How to send a notification from ASMX web services to ASP.NET MVC view?

0条回答
登录 后发表回答