-
Notifications
You must be signed in to change notification settings - Fork 1
RPC SOAP Programming Model
The request and response methods are defined as Boost Serializable types. For example if we are creating a simple Calculator webservice a request could be represented with the following struct:
struct CalculatorRequest {
double operand1;
double operand2;
char operation;
template<class Archive>
serialize(Archive &ar, const unsigned int /∗ version ∗/) {
ar & BOOST_SERIALIZATION_NVP(operand1);
ar & BOOST_SERIALIZATION_NVP(operand2);
ar & BOOST_SERIALIZATION_NVP(operation);
}
};
The struct is comprised of two doubles, the operands, and a char representing the operation (* for multiplication, / for division, etc).
The calculator service response can be defined as:
struct CalculatorResponse {
double result;
std::string text;
template<class Archive>
serialize(Archive &ar, const unsigned int /∗version∗/ ) {
ar & BOOST_SERIALIZATION_NVP(result);
ar & BOOST_SERIALIZATION_NVP(text);
}
}
Where result is the requested operation result, and text is the full string representation of the request.
A service and it's various operations are represented through accesible member functions of user defined types.
The calculator example can be declared as:
class MyService{
public:
CalculatorResponse calculator(const CalculatorRequest &request);
};
To register the created service in answer you can use the ANSWER_REGISTER_OPERATION to register each of the member functions you want as web operations.
ANSWER_REGISTER_OPERATION(MyService::calculator);
This will register the operation calculator. The classname (MyService) is discarded, as the project name is used instead for the service name.