Newsletters Subscriptions Media Kit About Us Contact Search Home

Stuff
OS/400 Edition
Volume 2, Number 5 -- February 27, 2003

Web Services and the AS/400


by Rick Farina

The Internet has permeated our environment and the AS/400 is being called upon to play its part. But let's be clear. We're not talking about content-driven sites or those hosted by the company ISP. This is about Web-based applications that provide real-time data access, transaction processing, and reporting. Client demands have driven this change. What is certain is that the AS/400 is ready today. What is not so clear is whether AS/400 programmers are prepared to meet this challenge.

A Simple Test

If asked by management to provide guidance and expertise for Web-based strategies, what advice would you give? Would you be able to articulate the difference between WebSphere, Microsoft .NET, and the various tools and technologies claiming to get you there faster, quicker, and "hassle-free"? Would Web services and XML be part of your conversation, or would they be considered "phase two" material? To survive in the Web world as AS/400 programmers, we need to be prepared to answer these questions, and be equally comfortable providing the solutions.

Platform Choices: Where Do I Begin?

Without doubt, the landscape continues to unfold and the battle for the desktop and enterprise continues. IBM, Microsoft, and Sun Microsystems endlessly push their particular technology and insist that it provides benefits not realized by the others. To some degree, each has a valid argument. But if you look a little closer, you'll see two technologies that are common to all vendor offerings: Web services and XML.

IBM and Microsoft have gone to great lengths to ensure that Web services and XML are being incorporated and supported in every technology offering they have. This includes databases, operating systems, Web sites, and utilities. Sun, Oracle, and the Linux community have followed suit. In fact, the entire computing industry has fully committed to and embraced Web services and XML. We, as AS/400 programmers, must now do the same.

Web services is the focus of this article. In this, the first of a two part series, we will examine what Web services are and how they are being used. We will go through the steps of creating a Web service using current technology. At the conclusion of this article, you will be able to create and execute a Web service on your own Web site. In part 2, we will build an application to consume the Web service programmatically, and show how to make AS/400 data available through the same service we are building here today.

Web Services: Putting It in Perspective

We are all familiar with using a browser to make an HTTP request of a Web server, and having the Web server, in turn, display an HTML page. What many of us may not be aware of is that program requests can be made via the same HTTP protocol with or without the implementation of a browser, user interface, or user interaction. This is the underlying essence of Web services.

Web services allow for program-to-program calls, using the Internet as the transport medium. Because HTTP is used as the transport protocol, Web service requests have no problem traversing firewalls to arrive at their final destination. This allows your clients to incorporate AS/400 applications into their desktop programs, if you allow them to. This is a very powerful concept, but it's only the tip of the iceberg.

Web services are similar to CL programs in that they do not have a visual component, but they do possess a well-defined interface through which other programs can communicate. Like CL programs, Web services expect certain parameters, of specific types, in a specific order. Unlike CL programs, however, Web services only exist on a Web server and return all requested data in XML format.

Web services also provide another unique quality. You can look introspectively at a Web service, and it will expose everything you need to know about calling it, including its input and output parameters and types. This can be done programmatically or via a browser. We'll see this in action shortly.

This article will show you how to use Microsoft's Visual Basic .NET to create a Web service and use a browser to consume it. Let's get started.

Creating a Web Service Using VB. NET

In Figure 1, a simple Web service is created that expects a single parameter of type Integer called Employee Number, and returns a single parameter of type String called Employee Name.

Using Microsoft's Visual Studio .NET, I create a New Project of type ASP.NET Web Service. I call the project MidrangeServer and store it in my local Web site, called WebServices.

This creates a series of files, along with a default program called WebServices1.asmx, which contains a single function called HelloWorld. For this example, I have renamed WebServices1.asmx as EmployeeService.asmx, and have replaced it with the code shown in Figure 2. When the method is called, it will determine what value was received for EmployeeNumber. If either 1 or 2 is received, a valid EmployeeName is returned. Anything else is considered invalid, and the appropriate message is sent back.

There are a few things that should be understood about this Web service. First, it is comprised of a single class named EmployeeService, which contains a single method named GetEmployeeName. The Web method is prefixed with the attribute WebMethod. This attribute is what distinguishes the method as a Web method, as opposed to a traditional method. (Note that the default style and formatting is set to Document/Literal but can be modified, via attribute settings, to RPC/Encoding.)

It is important to note that nowhere are we formatting the returned data in XML. This is automatically handled by the Web service, thus making our job as easy as retrieving the data, something we all know how to do very well.

To create the actual Web service object, I execute the Build function from within .NET. With a clean compile, I am now ready to have the Web service consumed. By loading an XML-aware browser (such as Internet Explorer) and pointing at the URL http://localhost/WebServices/MidrangeServer/EmployeeService.asmx, I receive the screen shown in Figure 3.

This browser view is very interesting and worth reviewing in some detail. First, notice that both the names of the class (EmployeeService) and the Web method (GetEmployeeName) are recognized. If I had other Web methods exposed in my EmployeeService class, they would be listed as well.

If I continue, by clicking the method's hyperlink, the input/output parameter requirements are exposed, along with three possible ways of communicating with the Web method. (Only the SOAP request/response is shown in Figure 4, but HTTP Get and HTTP Post can also be used.)

If I now enter a legitimate value for EmployeeNumber (in this case, 2) and invoke the method, the actual program will be executed and the corresponding XML response will be returned, as shown in Figure 5.

In a real-world situation, the calling program would be responsible for parsing and processing the returned XML document. We will see this in action in Part 2 of the series. In this example, however, the browser has recognized and interpreted the XML and displayed it accordingly.

A Quick Review

It should be obvious at this point that I didn't need to do much to create and consume a Web service. That's because the underlying technology handled many of the complexities for me. Although I have focused on Microsoft's .NET platform in this example, similar results can be achieved using technologies found in the IBM, Sun, and Linux worlds. For information on IBM's Axis technology and an overview of Simple Object Access Protocol (SOAP), check out David Morris's article "iSeries Web Services Revolve on Free Axis." For more information on XML, read David's articles "Getting Started With XML," "Validating XML with a Document Type Definition," and "Configuring Applications with XML," in this issue of Midrange Programmer.

Where To Go From Here

Experience dictates that the most successful AS/400-to-Web applications involve existing IT staff, in this case RPG programmers. The greatest failures are those where outsourced companies create the applications in a vacuum and throw them "over the fence" to the IT department for integration with its back end. If you're going to own it eventually, it might as well be up front.

As an AS/400 programmer, you owe it to yourself to get up to speed on the possibilities offered by Web services and XML. In my next article, I will close in on the steps needed to make my AS/400 data and programs part of this Web service and have it send requests to, and return the requested data directly from, the AS/400. Stay tuned!


Rick Farina is president of Farina + Associates, a consulting firm based in Boston that focuses on Web and Windows applications for the AS/400. Rick is a frequent speaker at COMMON and ASNApalooza and has written several articles on taking the AS/400 to the Web. In 1993, Rick was the lead architect and designer of the application that won the Computerworld-Smithsonian Award for Information Technology in Transportation. Rick can be reached at rfarina@farina-assoc.com.


Sponsored By
INFORMATION AVAILABILITY INSTITUTE

Why The Information Availability Institute?

To arm you with the knowledge, skills, tools, and strategies you need to help you minimize or eliminate your downtime threats.

The Information Availability Institute (IAI) is dedicated to developing and promoting best practices in Information Availability, Business Continuity and Disaster Recovery with a focus on the management and interrelationship of six key technical disciplines found within every information enterprise:

  • Networks
  • Applications
  • Security
  • Database
  • Servers
  • Storage

The Information Availability your organization needs can only be achieved through the harmonization and optimization of these six areas.

Best Practices for IT Professionals
The Institute offers Training and Certification Courses, Workshops, Webcasts, and Seminars (at selected locations throughout North America) to help IT professionals develop and manage effective Business and eBusiness Availability solutions for their Disaster Recovery, Business Continuity, and Contingency Planning needs. The IAI develops its best practices and course materials by drawing from the expertise of a team of skilled professionals with decades of field experience in developing and deploying Availability, Business Continuity and Disaster Recovery solutions. These experts have served some of the world's most trusted names in Banking, Securities Exchange & Insurance, Manufacturing & Distribution, Multi-Channel Retailing and eCommerce, Healthcare, and more.

Strategy & Planning Guidance for Managers
Today's real-time enterprise demands Information Availability for increased profitability and reduced financial risk. Unexpected events-caused by Mother Nature, technology failures, cyber attack, human error and more-can threaten your organization's ability to function as a business. And today, your corporation's stockholders, your CEO and Board of Directors and even your supporting financial institutions, are all looking for increased protection for your business and are requiring more accountability of those responsible for providing it. This is exactly why the IAI also offers introductory Availability Strategies education for Managers and Business Executives who are responsible for Disaster Recovery, Business Continuity, and Contingency Plans for their organization's data and applications.

The Information Availability Institute is pleased to offer
FREE Availability & Business Continuity Workshops.
Register Online at
www.AvailabilityInstitute.org/WorkShop


THIS ISSUE
SPONSORED BY:

T.L. Ashford
ASNA
Information Availability Institute
Profound Logic Software


BACK ISSUES

TABLE OF
CONTENTS
iSeriesMonitorME: Set Up a Wireless Development Environment

Configuring Applications with XML

Web Services and the AS/400

The New CHAIN Operation: This Is Not Your Father's CHAIN Op Code


Editors
Shannon O'Donnell
Kevin Vandever

Managing Editor
Shannon Pastore

Contributing Editors:
Howard Arner
Raymond Everhart
Joe Hertvik
Ted Holt
David Morris

Publisher and
Advertising Director:

Jenny Thomas

Advertising Sales Representative
Kim Reed

Contact the Editors
Do you have a gripe, inside dope or an opinion?
Email the editors:
editors@itjungle.com


Copyright © 1996-2008 Guild Companies, Inc. All Rights Reserved.