- Existing Web Services
- Exposing Systems as Web Services
- Clustering Methods Usefully
- About This Article
Exposing Systems as Web Services
The core of a Web service is the set of SOAP interfaces it implements. Each interface is defined in terms of an object to which it's attached, a method that it implements, and the parameters that it accepts and emits. For instance, a SOAP interface to log into a job-posting site might be implemented as a method called getLoginToken attached to an object called Jobs. The getLoginToken method might accept parameters called username and password and return a parameter called token. The method would be one of many implemented as part of the Jobs object, which together would make up the full Web service.
In Perl, SOAP::Lite is the preferred tool for implementing SOAP interfaces. SOAP::Lite enables each SOAP method to be defined as a subroutine with either named or unnamed parameters used as the arguments for the method. SOAP objects are represented as Perl modules, so the process for creating a full Web service would follow the standard procedures for creating modules in Perl. For instance, the Jobs object mentioned could be created using SOAP::Lite and a module named Jobs.pm, with subroutines named getLoginToken and so on. SOAP::Lite handles most thorny data serialization problems, so object references, session variables, and authorization tokens all can be implemented in a Perlish fashion.
When deciding how to implement a Web service for an existing HTML-based project, consider the work that already has been performed. If existing Web interfaces can be wrapped in a set of subroutines, considerable effort can be avoided. Form variables can be serialized easily into method parameters, and method names can be derived from existing page names, if necessary. Most of the work then would lie in encoding the output in a SOAP-friendly format rather than in an HTML-formatted page.
After creation, Web services can be reused also as the back end of a standard Web site. Object methods created for use with SOAP::Lite can be used with local Perl programs as well, so it's possible to encapsulate all the logic of a site in the object modules and use them with both. This reduces the job of the Web site designers to simply translating form requests into method calls and formatting the results using HTML templates.