Home > DeveloperSection > Forums > Asynchronous callback from web api controller
john rob

Total Post:108

Posted on    December-17-2013 12:56 AM

 C# C# 

 1 Reply(s)
 1183  View(s)
Rate this:

I'm very new to Web API and I have an unusual pattern that I need to implement. In the Post method of my controller, it is to take an object which includes a CallbackURL. It will then immediately return an HTTP response to the caller. Afterwards, it will use a 3rd party, off-site API to perform some work with the object. Once that work is done, the controller is to post the results of that work to the CallbackURL.

However, I do not know how to implement this in Web API. Once I return the HTTP response, the controller's lifecycle is over, correct? If so, how do I perform the work I need to do after I return the response?

Pravesh Singh

Total Post:411

Posted on    December-17-2013 1:32 AM

Hi John,

If you only need to post results to a url and not to the client that initiated the call, you could possibly do something as easy as this:

public string MyAPIMethod(object input)


    Task.Factory.StartNew(() =>


        //call third-party service and post result to callback url here.       


    return "Success!";


The api call will return right away, and the Task you created will continue the processing in a different thread.

Don't want to miss updates? Please click the below button!

Follow MindStick