Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to achieve Asp.net MVC OneWay/FireAndForget call like WCF does?

In WCF you have something like this

[ServiceContract]
public interface IDoAuditService
{
    [OperationContract(IsOneWay = true)]
    [WebInvoke]
    void Audit(AuditEntry auditEntry);
}

Which as a result will allow the consumers to issue a request and continuing the flow without waiting for a response.

I've tried Asp.net MVC with AsyncController but the consumer will still block and wait until the callback will be called in the controller.

What I want is to use Asp.Net MVC but the behavior WCF like, I want to issue a request and continue the flow without waiting the request to be processed

like image 670
ruslander Avatar asked Jun 20 '12 14:06

ruslander


Video Answer


1 Answers

What about performing the action body async on the server and just returning to the caller immediately. It's not exactly a fire and forget but it will emulate that.

public ActionResult MyAction()
{
    var workingThread = new Thread(OperationToCallAsync);
    workingThread.Start();

    return View();
}

void OperationToCallAsync()
{
    ...
}
like image 106
Dan Carlstedt Avatar answered Sep 28 '22 00:09

Dan Carlstedt