http_listener invalid arguments in linux

Oct 22, 2013 at 2:26 PM
Hey,
I'm trying to use the Casablanca Lib 1.3.0 on Ubuntu 13.04. I've followed the documentation to build the Lib. I didn't got any error messages. Now I'm trying to use it in Eclipse and I think that I have included the right Paths. After that I'm trying to implement a simple http-listener with some json.

include <cpprest/http_listener.h>

include <cpprest/json.h>

using namespace web;
using namespace web::http;
using namespace web::http::experimental::listener;

include <iostream>

include <map>

include <set>

include <string>

std::map<utility::string_t, utility::string_t> dictionary;

void handle_get(http_request request)
{
TRACE(L"\nhandle GET\n");

json::value::field_map answer;

for(auto const & p : dictionary)
{
  answer.push_back(std::make_pair(json::value(p.first), json::value(p.second)));
}

request.reply(200, json::value::object(answer));
}

int main()
{
 http_listener listener(U("http://localhost/restdemo"));

 listener.support(methods::GET, handle_get);
     return 0;

     try
{
  listener
     .open()
     .then([&listener](){TRACE(L"\nstarting to listen\n");})
     .wait();

  while (true);
}
catch (exception const & e)
{
  wcout << e.what() << endl;
}
}

But I get the following error Message
Invalid arguments '
Candidates are:
void support(?)
void support(const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &, ?)
' RestListener.cpp /RestListener/src line 41 Semantic Error
Oct 23, 2013 at 12:03 AM
Hi hsgimit,

In the future when sharing code could you please use the 'Insert Code' CTRL + K option. It makes it a lot easier to read and share.

I tried out your code, making a couple of small changes, removing the TRACE calls, adding std:: namespace prefix, and removed the return 0; right in the middle of main. Afterwards I had no trouble compiling on Ubuntu. Is there more to error message you can post or are you getting other errors as well? Also taking a look at our test cases can help you get using the Casablanca library. Our tests easily cover cases like this.

Here is the code I was able to compile:
#include <cpprest/http_listener.h>
#include <cpprest/json.h>

using namespace web;
using namespace web::http;
using namespace web::http::experimental::listener;

#include <iostream>
#include <map>
#include <set>
#include <string>
std::map<utility::string_t, utility::string_t> dictionary;

void handle_get(http_request request)
{
    json::value::field_map answer;
    for(auto const & p : dictionary)
    {
        answer.push_back(std::make_pair(json::value(p.first), json::value(p.second)));
    }
    request.reply(200, json::value::object(answer));
}

int main()
{
    http_listener listener(U("http://localhost/restdemo"));

    listener.support(methods::GET, handle_get);
    try
    {
        listener.open().then([&listener](){}).wait();
        while (true);
    }
    catch (std::exception const & e)
    {
    }
    return 0;
}
Thanks,
Steve
Oct 23, 2013 at 11:44 AM
Hi Steve,
thanks for your fast response. I've tried your code too, but I'm still getting the same error
Description Resource    Path    Location    Type
Invalid arguments '
Candidates are:
pplx::details::_ContinuationTypeTraits<#10000,void>::_TaskOfType then(const #10000 &, pplx::task_options)
pplx::details::_ContinuationTypeTraits<#10000,void>::_TaskOfType then(const #10000 &, pplx::cancellation_token, pplx::task_continuation_context)
'   restListener.cpp    /RestListener/src   line 31 Semantic Error
Description Resource    Path    Location    Type
Invalid arguments '
Candidates are:
void support(?)
void support(const std::basic_string<char,std::char_traits<char>,std::allocator<char>> &, ?)
'   restListener.cpp    /RestListener/src   line 28 Semantic Error
Description Resource    Path    Location    Type
Method 'wait' could not be resolved restListener.cpp    /RestListener/src   line 31 Semantic Error
Is there everything else I have to consider, except including the path to the include files? I'm also using the -std=c++11 command.
Thanks,
hsgimit
Nov 7, 2013 at 4:10 PM
Hi hsgimit,

Sorry for the delayed response this time on my part. Can you also share the build command and what compiler version you are using?

Thanks,
Steve
Nov 8, 2013 at 3:33 AM
Hi hsgimit,

I see now that you responded to another thread and have it working.

Thanks,
Steve