Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
169 views
in Technique[技术] by (71.8m points)

javascript - How to get notification from web service to ASP.NET MVC view

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...