The Request-Response Service Operation Call
As another part of client initialization, the subscribe()method sends location and transport information to the weather service so the client can receive weather updates via its listener.
// set up the service proxy
rwsf::Transport transport; //1
if (transportName.empty()) {
transport = rwsf::TransportManager::findTransportByUrl(location);
} else {
transport = rwsf::TransportManager::findTransport(transportName);
WeatherSummaryProxy proxy = WeatherSummaryProxy::make(transport); //2
// subscribe to the WeatherSummary service.
std::cout << "Subscribing to WeatherSummary service..." << std::endl;
std::string host = listener.getProperty("bound-ip"); //3
std::string port = listener.getProperty("bound-port");
std::string scheme = listener.getProperty("name");
bool status; //4
std::string msg;
proxy.subscribe(host, port, scheme, status, msg); //5
if (status) { //6
std::cout << "Subscription successful." << std::endl;
else {
std::cerr << "Subscription failed: " << msg << std::endl;
return 1;
//1 Using logic similar to that for creating the listener, determines the transport to be used in creating the proxy.
//2 Creates the proxy based on the transport object passed into the static make() method.
//3 Acquires server, port, and transport scheme information from the listener.
//4 Creates two objects to be passed in the service request that will hold the response data.
//5 Sends the subscribe request message.
//6 Prints out information about whether the subscription succeeded based on the status value returned by the request. The status value is based on the results of the verifySubscription() solicit-response operation on the server. This operation simply sends a request to the client, which responds true if the request is received. See Implementing the Client-Side Notification and Solicit-Response Endpoints for the code.
The client also implements an unsubscribe() method that is very similar to subscribe().