Asynchronous callback from web api controller

Total Post:108


 2253  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?

  1. Re: Asynchronous callback from web api controller

    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.

      Modified On Apr-03-2018 07:07:47 AM


Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.