VS 2010 upload Code nested Loop issue ?

Oct 31, 2014 at 10:08 AM
Edited Oct 31, 2014 at 10:11 AM
Hello,
i'm trying to upload some files to a Webservice. The code looks like this:

return Concurrency::streams::file_stream<unsigned char>::open_istream(L"myfile.txt").then([](pplx::task<Concurrency::streams::basic_istream<unsigned char>> previousTask) -> pplx::task<void>
{
    try
    {
        auto fileStream = previousTask.get();

        // Make HTTP request with the file stream as the body.
        web::http::client::http_client client(L"http://www.fourthcoffee.com");
        return client.request(web::http::methods::PUT, L"myfile", fileStream).then([fileStream](pplx::task<web::http::http_response> previousTask)
        {
            fileStream.close();

            std::wostringstream ss;
            try
            {
                auto response = previousTask.get();
                ss << L"Server returned returned status code " << response.status_code() << L"." << std::endl;
            }
            catch (const web::http::http_exception& e)
            {
                ss << e.what() << std::endl;
            }
            std::wcout << ss.str();
        });
    }
    catch (const std::system_error& e)
    {
        std::wostringstream ss;
        ss << e.what() << std::endl;
        std::wcout << ss.str();
    }
}).wait();
Error:
no suitable user-defined conversion from "pplx::task<pplx::details::_BadContinuationParamType>" to "pplx::task<void>" exists

It would be nice if anyone has a suggestion.

Thanks.
Oliver
Coordinator
Nov 4, 2014 at 4:13 AM
Hi Oliver,

Could you let us know what version of the C++REST SDK you're using, what compiler you're using, and what OS you're using?

Thanks,
roschuma
Nov 10, 2014 at 8:17 AM
Hi,

sorry for the few details. I'm using version 1.2.0 the last compatible with VS 2010. OS: Windows 7 64bit with VS 2010.

Hope you can help.

Thanks,
Oliver
Coordinator
Nov 10, 2014 at 6:44 PM
Hi,

First off, we unfortunately no longer support VS2010, so if this turns out to be a bug in the library, any fix we make (or have already made!) won't be available.

However, I think I see at least one problem with your code. In the outer try/catch block, you return a task in the try section, but do not return anything in the catch section. In your case, I think it would be appropriate to use some invocation of pplx::task_from_exception to create a dummy task out of an exception object in the catch code.

roschuma
Nov 10, 2014 at 8:55 PM
I know for sure that there was a bug fixed recently where the library was unable to download/upload files bigger than 4 GB, so you should check for that too (it resulted in an infinite loop).
Nov 11, 2014 at 1:52 PM
Hi,

ok i dont get this to work. I know visual Studio 2010 and version 1.2.0 is no longer supported but can sombody point me to an example of uploading a file to a webservice for version 1.2.0 (This one doesn't work: http://msdn.microsoft.com/en-us/library/jj950081.aspx). I looked for examples in the Internet but I wasnt successful.

Thanks,
Oliver