我有一个web api,内部发出多个web api调用,并在结束时返回一个结果。这些多种方法需要不同的时间来执行,因此我在我的函数中获得了超时异常。
例如:
DeleteAccount是我的web api方法,它调用另一个web api方法DeleteExistingAccount。这个DeleteExistingAccount有多个方法调用,比如method1,method2,method3,method4。由于这些是异步执行的,我在DeleteAccount方法中遇到了Timeout错误。
如何实现method1,method2,method3,method4一个接一个地同步执行。
/////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;
}
由于 塔拉克