This article originally published in the Architects Corner section of our LANSA Review customer magazine Issue 33, 2006.
There is a wealth of material on the Web and in print about Web services, so rather than formal definitions, technical specifications and standards, this article will describe Web services in a less formal and more practical way. First, we will look at what Web services can do for you, their relationship with Service Oriented Architecture (SOA) and why you do need to understand all this. Then we will outline how LANSA Integrator takes the complexity out of implementing Web services for LANSA and 3GL developers alike.
This is just a brief outline of how to implement Web services using LANSA Integrator. Web services are just one of the many "Java services" you can rapidly integrate into your IBM i, Windows or Linux business applications with LANSA Integrator.
What can Web services do for you?
Web services are "Web services" not because you access them through your browser, but because you implement them using Internet protocols and standards such as XML and HTTP over a common, shared infrastructure backbone.
By using Web services you can turn the most traditional character-based or batch application into an Internet application. By this, I do not mean that a colorful, graphically rich interface will magically replace your 80 x 24 green-screens. What I mean is that if your application is enhanced or extended to offer or implement some of its functionality by means of Web services, then it becomes an Internet application. This can become an important aspect of application modernization — in some cases, the only aspect that really matters.
You can think of Web services as a highly abstracted means of calling and exchanging information between programs. The crucial difference from traditional techniques is that you don't need to know any details of the program implementation. You don't need to know what language the other program is written in, what operating system it runs on, whether it uses EBCDIC or ASCII, what protocols are necessary to invoke it or where it is located.
In the simplest sense, Web services are a means of using or publishing application functionality from or to any other connected computer in your organization or across the world. The functionality is typically packaged up as discrete methods or operations, each receiving parameters or returning data.
What about Web services and Service Oriented Architecture?
The first thing to understand is that SOA is not a product, it is a design pattern or architectural style. SOA is independent of platforms, tools and standards and there are many possible ways of implementing an SOA. Web services are a concrete example of a set of standards and protocols that may be used to implement SOA. The common thread that binds the two is in the word "service."
One way to begin to realize the benefits of SOA is to implement Web services that can be combined to create a composite application, reused across multiple applications and replaced with an equivalent that exposes the same interface.
Why do I need to understand Web services?
One of the key trends in recent years has been the integration of business processes, both inside and outside an organization. There are many business drivers for this trend — such as streamlining business processes, improving data quality, increasing responsiveness, reducing inventory levels etc. — and the reality is that integration may not be at the discretion of the IT department, but rather be mandated by business requirements.
A second reason concerns application architecture. Many developers will claim to have been following the essential principles of SOA long before the term was coined. However the SOA approach can be distinguished from past architectural practice in two ways. Firstly, by an emphasis on interoperability through the use of widely accepted standards and secondly, by a view of services that is much closer to the business view.
The third reason concerns modernization of "legacy" applications. The term legacy seems to have acquired negative connotations when, in many cases, what we mean by legacy applications are those that are at the heart of the operation of most enterprises today.
Many of these applications were developed before the emergence of the trends discussed here and need to be adapted. Modernization can take many forms, but attaching Web service interfaces to existing applications can be one way to ensure their continued relevance. Compared to other processes this can often be a relatively inexpensive technique.
LANSA Integrator makes Web service implementation easier
LANSA Integrator provides a framework that allows easy integration between Java programs and business applications. Included amongst LANSA Integrator services are the SOAP Agent and SOAP Server which can be used to implement Web services. SOAP is an XML-based protocol for exchanging information over HTTP.
Using these services, organizations can enter the world of Web services with relative ease. LANSA Integrator offers a wizard-based approach to Web service development and hides the complexities of the protocols to present a simplified interface to developers. LANSA Integrator facilitates the mapping of XML data and automatically generates the supporting Java and XML objects.
What are SOAP Agents and SOAP Servers?
You define a SOAP Agent project when you want to consume (call) an existing Web service from your LANSA or 3GL application. In this case, the operations and parameters of the Web service are externally defined and you have to write your application to conform to that definition.
The publisher of the Web service will provide this definition in an XML document containing meta-data describing the Web service in a standard format using Web Service Description Language (WSDL). The LANSA Integrator SOAP Wizard takes care of importing the definition for you.
You define a SOAP Server project when you wish to publish a Web service from your LANSA or 3GL application that other applications can call. In this case, you have control over the definition of the operations and parameters that you describe using the SOAP Wizard. LANSA Integrator will then publish the description of your Web service for you using WSDL.
How do you implement Web services with LANSA Integrator?
Whether you are creating a SOAP Agent or SOAP Server project, you will complete the same basic steps using the LANSA Integrator SOAP Wizard and Studio to define your SOAP solution:
Step 1: Create a new solution using the LANSA Integrator Studio
The LANSA Integrator Studio (see Figure 1) provides a development environment for specifying configuration, mappings and other information for Web and Java services and acts as a central point for managing and deploying LANSA Integrator services and solutions.
You begin your Web services project by creating a new solution in the LANSA Integrator Studio. If you are creating a SOAP Agent solution, LANSA Integrator will prompt you to provide the WSDL for the Web service that you wish to use.
Step 2: Select Web Service Operations and Map Parameters
Using the SOAP Wizard (see Figure 2) you select the operations of the Web service you wish to consume in a SOAP Agent solution or define the operations and parameters of the Web service used in a SOAP Server solution.
In both cases, you map the inbound and outbound parameters for each operation to program variables in the way that best suits how you process them in your application.
Step 3: Create Your Application Code
LANSA Integrator Studio can help you get started by generating the outline RDML code for your application to use the SOAP solution you have defined.
In a LANSA RDML/RDMLX function, form, or reuseable part, you invoke LANSA Integrator services using LANSA Built-in Functions that are supplied for the purpose.
Although not illustrated here, you can also invoke LANSA Integrator services from 3GL applications — for example from an ILE RPG application — using a straightforward API.
SOAP Agent code example
Let's review the basic structure of the LANSA code necessary to call a simple Web service (see Figure 3):
- Connect and load: This step readies the program for calling the Web service by opening a Java Service Manager (JSM) connection and loading the SOAP Agent service. It then loads the EMPLOYEEAGENT Web service solution that was defined with the LANSA Integrator SOAP Wizard.
- Set operation and parameters: Next, you specify that you wish to call the GETEMPLOYEES operation of the Web service. The two SET PARAMETER commands "bind" the program variables #DEPTMENT and #SECTION to the corresponding parameters of the operation.
The Java Service Manager has access to the variables in the LANSA program by means of the SERVICE_EXCHANGE (*FIELD) keyword; it then knows which field to map to which parameter via the mappings that were specified in the SOAP Wizard.
- Execute / call: This code in this step executes (calls) the Web service and waits for the response.
- Retrieve and process results: This code executes the GET service command to retrieve the information for employees belonging to the department and section that were specified in the operation parameters.
- Unload and disconnect: When complete, you unload the service and close the connection to the JSM.
SOAP Server extends the reach of your applications
The LANSA code for a SOAP Server project has a very similar structure to that used for SOAP Agent. Your LANSA function will typically be invoked by an HTTP Server when it receives the Web service request.
The LANSA function needs to perform similar steps to connect to the Java Services Manager and load the SOAP Server service, identify and receive the request, process the request, then prepare and send the response and unload and disconnect.
The middle part, where your application-specific logic processes the request. This can include calls to existing LANSA or 3GL programs. You can expose the key functionality of existing applications to other applications without changing the original application code.
LANSA Integrator supports many other Java services
LANSA Integrator takes the complexity out of implementing Web services for a LANSA or traditional 3GL developer. But LANSA Integrator is not just about Web services.
In the simplest terms, LANSA Integrator provides a framework that allows easy integration between Java programs and business applications written using LANSA or 3GLs such as C, RPG or COBOL.
The SOAP Agent and SOAP Server services are just two of the services supplied by LANSA. LANSA Integrator comes with a range of services that handle common integration tasks such as processing XML, transporting data over common protocols such as FTP, HTTP or by e-mail and for creating and reading common file types such as PDF, ZIP, CSV and Excel workbooks.
These services expose a simple interface to the application developer that hides the complexity of interacting with a Java program or of dealing with the intricacies of the underlying transport method or protocol. It is also possible to write your own Java services.