Implementing the Request-Response Method Asynchronously
Following is the implementation of the request-response invoke() method in AsyncClient.cpp, the provided implementation of the client.
 
void invoke_longRunningMethod(AsyncProxy& proxy) //1
{
std::string input_in("Hello World");
std::string return_ret;
try {
std::cout << "Invoking longRunningMethod" << std::endl;
rwsf::CallInfo info;
rwsf::AsyncHandle handle =
proxy.longRunningMethodStart(info, input_in); //2
if(handle.isFinished()) { //3
return_ret = proxy.longRunningMethodEnd(handle); //4
// return_ret is ready for use!
// handle's callInfo has response headers, etc.
rwsf::CallInfo retInfo = handle.getCallInfo(); //5
}
else {
std::cout << "Still waiting" << std::endl;
return_ret = proxy.longRunningMethodEnd(handle); //6
}
std::cout << "Return value = " << return_ret << std::endl;
} catch(const rwsf::SoapFaultException& e) { //7
std::cout << "Fault Code: "
<< e.getFault().getFaultcode().asString() << std::endl;
std::cout << "Fault String: " << e.getFault().getFaultstring()
<< std::endl;
}
}
//1 A request-response method that simulates a wait in order to illustrate its asynchronous behavior.
//2 Calls the asynchronous process longRunningMethodStart() method.
//3 Tests whether the response is available, calling isFinished() on the handle.
//4 Retrieves the response.
//5 If the response message rwsf::CallInfo object has data of interest, retrieves the object so calls can be made against it.
//6 Calls the asynchronous process longRunningMethodEnd() method, which in this position causes the client to block until the response arrives.
//7 Catches an rwsf::SoapFaultException.