WebAPI GET method + IProgress RRS feed

  • Question

  • I'm trying to implement an Async Method in a WebAPI that would take as parameter some file Ids, would compress the files and return the url for the created zip file.
    There's a working environment to accomplish this, but we're trying to optimize its performance.
    Due to the architecture of our bussiness, the files can be hosted in one of our on premises servers, or in Azure. And there are some proxies in the middle, plus different Azure instances/containers.

    Curretly the approach is a traditional one: there's an API that takes the request, queries the database to check where the files are stored, sends a request to start compressing to the accordingly destination and returns to the client with a uri to check the progress status (currently stored in database)

    After some brainstorming meetings and trying to think outside the box, I've been trying to implement IProgress and CancellationToken with ajax requests.

    My idea is (knowing the location where the files should be compressed) to make an asynchronous request that can be aborted at any time, which also stops the process server-side, and that supports ajax progress report.

    Having something like the following method,

            public async Task<string> Test(IProgress<int> progress, CancellationToken token) {
                string response = await Task.Run<string>(() => {
                    for (var i = 1; i <= 100; i++) {
                        if (!token.IsCancellationRequested) {
                        else {
                            return "aborted";
                    return "OK";
                return response;

    making an ajax request throws error 415 Unsupported Media Type

    No MediaTypeFormatter is available to read an object of type 'IProgress`1' from content with media type 'application/octet-stream'.

    Note: I'm also trying to avoid using SignalR. I just want to have progress report over an ajax request that can be aborted

    José Villagrán

    Monday, November 13, 2017 8:22 PM

All replies

  • WebAPI can be discussed at the ASP.NET forum.


    Monday, November 13, 2017 10:32 PM
  • Hi Jose,

    According to your question is more related to ASP.Net , I will move the thread to ASP.NET Forum  for suitable support.

    The Visual C# discuss and ask the C# programming language, IDE, libraries, samples and tools . If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution .


    Neil Hu

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, November 14, 2017 9:29 AM