SOAP, or Simple Object Access Protocol, is the backbone of web services and a variety of new technologies. In this article Nauman shows us how to create a simple SOAP client with Visual C++. He describes several methods found in the SOAP toolkit, and finishes off by creating a SOAP client that checks whether or not a Yahoo user is currently online.
Building A SOAP Client With Visual C++ - Demonstrating a sample SOAP client (Page 4 of 5 )
For demonstrating the use of the SOAP classes that we've looked at in this article, I've used one of the services listed on http://www.xmethods.net/. The service indicates Yahoo Messenger's online presence. You can find the required details by following this URL. The only thing it expects is a method parameter i.e. the Yahoo user's login id. The result returned is a boolean value indicating 0 for offline and 1 for online. Other details are available on the site or by viewing the WSDL here.
Anyway, I guess the best way to learn something is to see the source code in action, so that's exactly what we will do now. Here's the C++ code for a console application that uses SOAP calls to find out if a Yahoo user is online:
// Connect to the service Connector.CreateInstance(__uuidof(HttpConnector)); Connector->Property["EndPointURL"] = "http://www.allesta.net:51110/webservices/soapx4/isuseronline.php"; Connector->Connect();
// Begin message Connector->Property["SoapAction"] = "uri:allesta-YahooUserPing"; Connector->BeginMessage();
// Create the SoapSerializer Serializer.CreateInstance(__uuidof(SoapSerializer));
// Connect the serializer to the input stream of the connector Serializer->Init(_variant_t((IUnknown*)Connector->InputStream));
// Send the message to the web service Connector->EndMessage();
// Let us read the response Reader.CreateInstance(__uuidof(SoapReader));
// Connect the reader to the output stream of the connector Reader->Load(_variant_t((IUnknown*)Connector->OutputStream), "");
// Display the result printf("Answer: %s\n", (const char *)Reader->RPCResult->text); CoUninitialize();
}
As you can see, the code is fairly straight forward, and even if you haven't worked with C++ before, then I'm sure that you can figure out what the code does: Firstly, it connects to the remote server. Secondly, it creates the SOAP message and sends it. Lastly, it reads the response from the server and outputs it to the screen with printf.