0

I Have a web api that internally makes multiple web api calls and retuns one result at the end. These multiple methods take different time to execute and as a result I'm getting timeout exception in my function.

For ex:

DeleteAccount is my web api method and it calls another web api method DeleteExistingAccount. This DeleteExistingAccount has multiple method calls say method1, method2, method3, method4. As these are executing asynchronously I'm getting Timeout error in my DeleteAccount method.

How can I achieve the method1, method2, method3, method4 to execute synchronously one after the other.

/////This is my web api method
public IHttpActionResult DeleteAccount([FromUri] string acctId, [FromUri] string email = "")
    {
            if (PicUpHelper.IsValidUserRequest())
            {
                string baseUrl = System.Configuration.ConfigurationManager.AppSettings["APIURL"].ToString();
                string url = string.Format("/api/deleteaccount/{0}", acctId);
                var clientRequest = new RestClient(baseUrl);
                var request = new RestRequest(url, Method.DELETE);


                IRestResponse response = clientRequest.Execute(request);
                //// When I look at the response I have the timeout here
                var content = response.Content; // raw content
                dynamic data = JsonConvert.DeserializeObject(content);
    }
}

///My web api method will invoke this web api method
 public WebApiResultEx<string, string> DeleteAccount([FromUri] string acctId, [FromUri] string email = "")
    {
        WebApiResultEx<string, string> oDelAcctRes = new WebApiResultEx<string, string>();
        Account oAccountInfo = new Account();
        MyDbContext DbCtxt = new MyDbContext();

        AccountAPIController oAccountAPIController = new    AccountAPIController();
        var oAcctInfo = oPlatAccountAPIController.Get(acctId);

      if (!oAcctInfo.HasError > 0)
            {
                oAcctInfo = (Models.Api.Account)(object)oAcctInfo.Data;

                //second method
                oRes = oAccountAPIController.DeleteAcct(acctId);
            }
    return oRes;
   }

Thanks Tarak

8
  • Possible duplicate of Call external api from Web API synchronously Commented Mar 30, 2016 at 8:04
  • Can you please show the code you are using? Commented Mar 30, 2016 at 8:45
  • @gabriel I have put the code can you kindly look and tell me where I'm going wrong Commented Mar 30, 2016 at 9:51
  • Okay a few things, 1. Why call different controller actions? I would suggest abstracting the code in the controller into service classes and then call those methods rather than the controllers directly. It makes it easier to reuse the code. 2. What is the exact error message your are getting? 3. How long do the methods take to execute? Commented Mar 30, 2016 at 9:57
  • @gabriel, the DeleteAccount is a proprietory code that we included in our project, we cannot merge the controllers. However we can find the solution and suggest to the client. They will update their controller and resends back. Commented Mar 30, 2016 at 10:04

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.