The Perl Journal May 2003
Iremember, lo these many years ago (okay, so it was only five years ago, but that's centuries in Internet time), reading Dave Winer's Davenet article about his new XML-RPC, which would use XML over HTTP to make remote procedure calls. "Huh?" I thought, "Isn't that what CGI does? All you have to do is return XML documents." So, I pretty much ignored it. Meanwhile, XML-RPC turned into SOAP, Pavel Kulchenko wrote SOAP::Lite, Randy J. Ray wrote RPC::XML, and the likes of Google and Amazon exposed SOAP interfaces to their services. So maybe it's time for me to take a closer look.
O'Reilly & Associates has been my touchstone over the years for technology-specific books, so their Programming Web Services with Perl, by Kulchenko and Ray, seemed like the obvious choice and, with the exception of a few quibbles about copyediting (not uncommon with first printings of O'Reilly titles, I'm afraid), it has proven to be a good choice. While I'm not yet convinced that I'm a fan of XML-RPC or SOAP, I will try in this review to keep my criticisms of web services in general separate from any criticisms of the book itself.
The book starts with an enjoyable, clear-headed overview of the state of web services today. The authors point out areas of hype and cynicism, and declare that the truth is somewhere in the middle between the points of view of web-services proponents and detractors. They then whet the reader's appetite with a couple of simple client applications for real-world web services.
The next chapter gives an overview of HTTP, XML, and XML Schema; the technologies on which the various web-service frameworks are built. The authors cover a lot of ground clearly and concisely.
In Chapter 3 we get an introduction to XML-RPC and its specifications, as well as barehanded implementations of a simple client and server. XML-RPC is a simple enough spec that it's possible to write applications using it without having to use a dedicated module (though I wouldn't recommend it). XML-RPC's chief virtue appears to be its simplicity, which is also its chief failing. Chapter 4 rewrites the barehanded examples using the three current XML-RPC libraries, RPC::XMLSimple, XMLRPC::Lite, and RPC::XML. From the point of view of the disinterested reader, there isn't really that much to choose from between the three toolkits shown; they all offer massive savings of programmer effort. The authors do describe the various trade-offs involved with each choice and show admirable restraint in their descriptions of the modules they themselves wrote. (It might please Randy J. Ray to know that, if I ever need to write an XML-RPC service, I'll use his RPC::XML module.)
Which brings us to Chapter 5. Described by the authors as an "XML bolus," Chapter 5 covers the low-level details of SOAP and I'm afraid it proved very hard to swallow. (Through no fault of the authors, I hasten to add.) As satirical songwriter Tom Lehrer once said, "I find that if you take the various popular song forms to their logical extremes, you can arrive at almost anything from the ridiculous to the obscene, oras they say in New Yorksophisticated." I'm still undecided as to whether SOAP is ridiculous or obscene, but it's certainly sophisticated. The authors do what they can to help the pill down though, and the reader is rewarded by arriving at the sunny uplands of Chapter 6, which deals with the basics of programming using SOAP, and more specifically, SOAP::Lite.
Interface is everything in SOAP::Lite. Kulchenko takes the crawling horror that is the SOAP spec and bundles it all up behind a really neat interface. Throughout the chapter, the authors use it to build increasingly complex applications, and the module just works, leaving the programmer free to concentrate on the business of solving the programming problem instead of the communication problem.
Chapter 7 continues to delight as we move on to the process of writing a SOAP server using the module. The authors concentrate on building a "wish list" application, similar to (but massively simplified, of course) Amazon's wishlist. Again, because the toolkit is so easy to use, the authors are free to concentrate on the process of designing an interface that's suitable for a web service, and on making sure that the choice of transport is decoupled from the application itself. This is all very neatly done; it wouldn't be hard to take the lessons learned in this chapter and apply them to developing your own web services.
Chapter 8 extends things still further by showing how SOAP services don't have to be accessed via HTTP. Examples are given using pure TCP sockets, Jabber, and even e-mail and FTP. Because of the care taken in designing the server application, the power of SOAP::Lite's abstraction, and a cunning trick with use and @ISA, this turns out to be a doddle. The chapter finishes with an example of writing a custom encrypted transport.
Chapters 9 and 10 cover WSDL and UDDI, which, from my point of view, is just more XML pain, I'm afraid. The exposition is again clear and helpful, though there did seem to be a higher incidence of typos in this chapter. I also noticed that some of the pseudo UUIDs used by the authors in the UDDI chapter weren't exactly standard: "FEEB-1E" and "EA8-69-COC5" don't look like any UUIDs I've ever seen.
Chapter 11 deals with the Representational State Transfer (REST) way of doing web services. At bottom, REST is a fancy name for my kneejerk response to XML-RPC from five years ago, but done right. Once again, the authors have done a great job of explaining the concepts involved with clarity, thoughtfulness, and some great example code. After reading their exposition, I have a much better understanding of what REST is, how to use it, why it's hard to get right, and why you should bother.
The last chapter deals with advanced topics, emerging standards for reliable messaging, distributed transactions, document- based processing, service discovery, the whole nine yards. The authors give an overview of the current state of the art. There's a good deal worth paying attention to in here, especially if you're interested in using SOAP internally for enterprise applications. There's also a useful section of internationalization issues and on improving application performance, which covers slightly more than the basic "use mod_perl;" rule.
The appendices include in-depth references for the XML-RPC and SOAP modules discussed in the main text, the full source code for all the examples discussed, and short but interesting Bibliography and Links sections.
After reading the book, I'm still not convinced by either XML-RPC or SOAP as technologies for reasons that I find hard to put my finger on, but convincing people like me wasn't the aim of the book. As both an overview of the various tools and techniques available and as a tutorial on the details of web-service implementation, this is an excellent book.
TPJ