简体   繁体   English

在等待110秒后再次从我的操作中触发,从另一个Web API调用Web API

[英]Calling a web api from another web api, after 110 seconds waiting my action fires again

I have a Web Api 2 it is calling another Web Api. 我有一个Web Api 2,它正在调用另一个Web Api。 The scenario is simple, I am uploading a file from Angular.Js then Angular calls a web api, this web api calls another web api. 场景很简单,我从Angular.Js上传文件,然后Angular调用了一个Web api,这个Web api调用了另一个Web api。 The last web api takes 2 minutes to respond, so when the first web api times out (after 110 seconds), it is fired again. 最后一个Web API需要2分钟才能响应,因此,当第一个Web API超时(在110秒后)时,它将再次被触发。 I have reproduced this issue in a clean environment and it is something that comes with Web Api. 我在干净的环境中重现了此问题,它是Web Api附带的。 The problem it is I don't know how to tell my web api, I need more time to receive the answer from my request. 问题是我不知道如何告诉我的Web API,我需要更多时间来接收请求的答案。

[HttpPost]
[MultipartContentValidator]
[ActionName("uploadfile")]      
// POST /api/documents/uploadfile?folderId={folderId}&assetId={assetId}
public async Task<HttpResponseMessage> UploadFile(int folderId, int assetId)
{
    IExternalWebApiCaller _caller = new ExternalWebApiCaller();
    //## If it is not multipart, we throw it away
    if (!Request.Content.IsMimeMultipartContent("form-data"))
    {
        throw new HttpResponseException(HttpStatusCode.BadRequest);
    }

    //## Getting the juice in memory instead of the harddrive
    var provider = await Request.Content.ReadAsMultipartAsync<InMemoryMultipartFormDataStreamProvider>(new InMemoryMultipartFormDataStreamProvider());

    //## We get access to the data
    NameValueCollection formData = provider.FormData;

    //## It will access to the files
    IList<HttpContent> files = provider.Files;

    //## Reading a file as bytearray and creating the model
    //## with the filename and stuff...if any
    if (files != null)
    {
        HttpContent filetobeuploaded = files[0];
        byte[] filebytearray = await filetobeuploaded.ReadAsByteArrayAsync();

        DocumentUploadViewModel model = new DocumentUploadViewModel();
        model.AssetId = assetId;
        model.FolderId = folderId;
        model.Data = filebytearray;
        model.Filename = filetobeuploaded.Headers.ContentDisposition.FileName.Replace("\"", "");

        return await _caller.CallWebApiHttpResponseMessage("api/document/uploadfile", HttpMethod.Post, null, model, GetHeaders());
    }
    else
    {
        //## Something fail (file with no content), so we kick this out
        throw new HttpResponseException(HttpStatusCode.NoContent);
    }
}

Any ideas how to avoid that? 任何想法如何避免这种情况?

Wep Api doesn't have a built-in mechanism to time out long requests, that means there is not way to extend the current time out. Wep Api没有内置的机制来使长请求超时,这意味着无法延长当前超时时间。

The best approach come by splitting the file in packages and send small packages one by one until the file is complete over both API's. 最好的方法是将文件拆分为多个包,并一一发送小包,直到通过两个API完成文件为止。 The last API will store the packages in Azure Blob Storage. 最后一个API将程序包存储在Azure Blob存储中。

Thanks for the replies. 感谢您的答复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM