omewhere north of a million. That, last time you counted, is the number of lines of C and C++ code keeping your organization running. And that is the number that runs through your head as you examine the literature surrounding Web services. The reason, of course, is that the bulk of information available on the subject is focused on developing Web services with Java, C#, Visual Basic, and other languages which, frankly, doesn't do you much good at all. Web services promises to make it easy to integrate C++ legacy systems with pretty much anything else, except for one catch: theres precious few products that support creating and deploying C++ Web services. This article provides an answer to this problem.
This article demonstrates how to write a SOAP client in C++. The client will exercise Google's SOAP-enabled search API, a service that accepts and answers search queries.
Resources for this Article
Before you begin writing any source code, it is necessary to get your house in order. You'll need to get a copy of Systinet's WASP Server for C++ that is appropriate for your environment, and Google's Developer's Kit. Both are free.
A Brief Introduction to Web Services
- WASP Server for C++
WASP is available for a variety of operating systems and compilers as a free download from Systinet's Web site. Even more appealing is that WASP is available for free deployment on single CPU machines. Purchasing a license is only necessary for deployment on multi-CPU hardware.
- Google Developer's Kit
You will need to download Google's developer's kit, although all youll really use from that is the WSDL file that describes their services and the license key. It takes only moments and costs you nothing to register with Google. It goes without saying that you'll need a C++ compiler. In my case, I am using Red Hat Linux 7.3 and gcc 2.96.
Unfortunately, this is not the place for an in-depth discussion of SOAP and WSDL. If you are unfamiliar with both, we recommend looking at the whitepaper, "Introduction to Web Services,
" or you can check out the Related Resources in the left-hand sidebar.
Briefly, SOAP (Simple Object Access Protocol) is the core protocol underlying Web services. It defines an XML envelope in which a developer can place an XML payload. This envelope can be delivered to a service over a variety of transports, such as HTTP and SMTP. Further, SOAP, WSDL, and the development environment you use help define a mechanism for delivering this payload in such a way as to mimic remote procedure calls (RPC). SOAP also specifies a means of encoding data in a language neutral format. WSDL (Web Services Description Language) is the key to SOAP interoperability. It defines the "what, how, and where" of your Web services. Technically, it's a published, static XML document that describes the data types your service consumes and returns (like arrays and structures), the allowed input and output messages, the various services available, and the URLs where they can be found.
Google has made a series of SOAP services that, among other things, provide access to Google's search functionality. Technically, thats all you need to know up front. Everything else you can glean from their WSDL document as you proceed with this tutorial.
|Editor's Note: Peter Lacey is an engineer for Systinet Corp.