Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/12/2014, 03:29
Macas
 
Fecha de Ingreso: noviembre-2012
Mensajes: 136
Antigüedad: 11 años, 6 meses
Puntos: 0
C++ Rest SDK para web service

Buenas,

Llevo ya unos dias investigando sobre como hacer un web service en C++, tengo muchas dudas y no se por donde empezar.
He estado instalando el sdk desde el nuget del visual studio 2010 y he probado el codigo de ejemplo de la web, para así poder entender un poco como va esto:

Código C++:
Ver original
  1. #include <cpprest/http_client.h>
  2. #include <cpprest/filestream.h>
  3.  
  4. using namespace utility;                    // Common utilities like string conversions
  5. using namespace web;                        // Common features like URIs.
  6. using namespace web::http;                  // Common HTTP functionality
  7. using namespace web::http::client;          // HTTP client features
  8. using namespace concurrency::streams;       // Asynchronous streams
  9.  
  10. int main(int argc, char* argv[])
  11. {
  12.     auto fileStream = std::make_shared<ostream>();
  13.  
  14.     // Open stream to output file.
  15.     pplx::task<void> requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile)
  16.     {
  17.         *fileStream = outFile;
  18.  
  19.         // Create http_client to send the request.
  20.         http_client client(U("http://www.bing.com/"));
  21.  
  22.         // Build request URI and start the request.
  23.         uri_builder builder(U("/search"));
  24.         builder.append_query(U("q"), U("Casablanca CodePlex"));
  25.         return client.request(methods::GET, builder.to_string());
  26.     })
  27.  
  28.     // Handle response headers arriving.
  29.     .then([=](http_response response)
  30.     {
  31.         printf("Received response status code:%u\n", response.status_code());
  32.  
  33.         // Write response body into the file.
  34.         return response.body().read_to_end(fileStream->streambuf());
  35.     })
  36.  
  37.     // Close the file stream.
  38.     .then([=](size_t)
  39.     {
  40.         return fileStream->close();
  41.     });
  42.  
  43.     // Wait for all the outstanding I/O to complete and handle any exceptions
  44.     try
  45.     {
  46.         requestTask.wait();
  47.     }
  48.     catch (const std::exception &e)
  49.     {
  50.         printf("Error exception:%s\n", e.what());
  51.     }
  52.  
  53.     return 0;
  54. }

No puedo ejecutarlo ya que me salen los siguientes errores

pplx::task<void> requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile)

Me dice que fstream --> Error: no existe ninguna conversión adecuada definida por el usuario de "pplx::task<pplx::details::_BadContinuationParamTy pe>" a "pplx:task<void>"

Alguna idea?

Despues de crear el proyecto he echo boton derecho y he añadido el sdk desde el NuGet package Manager.

No se si alguien me puede dar una mano con esto.

Saludos