Skip to content
Rodrigo Fernandes edited this page Oct 10, 2013 · 1 revision

Installing Answer

Downloading the source code

You can either pick a tagged release or clone the master repository

Alternativelly you can also use a git client to clone the repository:

git clone https://github.com/rfernandes/answer

Building from source

Dependencies

  • Boost Libraries >=1.42.0

Depending on the desired adapters, dependencies are as follows:

  • Native apache module - apr (>=1.4.8) and apreq2 (>=2.13)

  • Axis2C - axis2c (>=1.6)

  • FastCGI - fastcgi++ (>=2.1)

  • CPPNetlib - (incomplete/experimental) - cppnetlib (>=0.10)

    cd build cmake .. -DAPACHE_ADAPTER=ON -DFCGI_ADAPTER=ON make make install

Your first Answer Webservice

Let's start with a simple hello world example assume we have this code:

class ExampleService{
public:
  std::string hello_world(const std::string &name);
};

To make Answer aware of the operation we register it with the following macro

ANSWER_REGISTER_OPERATION(ExampleService::hello_world);

Compile and link against answer, and refer to the chosen adapter documentation on how to publish it.

Calculator Webservice

Answer requires that the request and response types of the operation be serializable with boost serialization. In the "hello world" example we used std::string, the serialization of which is provided by answer. For the following custom types serialization is specified via the templated serialize method.

struct CalculatorRequest{
  double operand1;
  double operand2;
  char operation;

  template<class Archive>
  void serialize(Archive &ar, const unsigned int /*version*/){
    ar & BOOST_SERIALIZATION_NVP(operand1);
    ar & BOOST_SERIALIZATION_NVP(operand2);
    ar & BOOST_SERIALIZATION_NVP(operation);
  }
};

struct CalculatorResponse{
  double result;

  template<class Archive>
  void serialize(Archive &ar, const unsigned int /*version*/){
    ar & BOOST_SERIALIZATION_NVP(result);
  }
};

Again we register the webservice using:

ANSWER_REGISTER_OPERATION(MyService::calculator);
Clone this wiki locally