Implementing the One-Way Method Asynchronously
This section discusses implementing a one-way method asynchronously. Even though a one-way method expects no response, you may wish to implement it asynchronously, allowing you to make another call on the proxy without waiting for the transport to return.
This discussion assumes background knowledge on one-way methods and how they work. For information, see The One Way Pattern.
Now let’s look at the implementation of the one-way invoke() method in AsyncClient.cpp in the <installdir>\examples\Async directory.
void invoke_oneWayMethod(AsyncProxy& proxy) //1
std::string input_in("Hello World");
rwsf::CallInfo info;
std::cout << "Invoking oneWayMethod" << std::endl; //2
rwsf::AsyncHandle handle = //3
proxy.oneWayMethodEnd(handle); //4
std::cout << "Finished executing the one way method"
<< std::endl; //5
//1 Invokes a one-way method that expects no response.
//2 Because no response is expected with a one-way method, the generator prints “Invoking one-way method” to std::out to indicate to the user that the service is doing its work.
//3 Calls the asynchronous oneWayMethodStart() on the proxy, assigning the result to an async handle. This method returns immediately, even though not everything necessary may have been done to send the message.
//4 Calls the oneWayMethodEnd() method, while it may seem counter-intuitive for a one-way method, allows the main thread to block until the thread that is preparing and sending the one-way message has completed its work. This also protects against exiting the program while the threads are still executing.
//5 Note that there is no catch block for rwsf::SoapFaultException exceptions for one-way operations, since they will never be thrown.