How does a webservice work on AS400, iSeries or IBM i Server?

How does an IBM i Server talk to the Internet?

If this is the first time you are creating a webservice, or if you just want to see some RPG code examples then you've come to the right place!

If you read the first lesson, your eyes may already be glazing over. All this talk of XML, JSON, WSDL, SOAP, REST, RPC sounds  kind of complicated right?

Don't worry - Webservices are (secretly) very simple

Why? Because a webservice is, by it's nature, a focussed piece of code that is asked one thing and responds with a clear simple answer.

Web services should be designed to stay as minimal, fast and efficient as possible.

  • The WEBSERVER handles the connection from your machine to the internet
  • The web server is the configuration that talks, and listens, to people on the internet. It handles all the communication styles and languages
  • The WEBSERVICES handles the data responses from your machine to the internet
  • Webservices are small components within a webserver that handle the business logic.

The Web Server provides a convenient way to externalize existing programs running on IBM i, such as RPG or COBOL, as Web services. This allows Web service clients to interact with IBM i program based services from the Internet or intranet using Web service based industry standard communication protocols such as SOAP.

IBM i Integrated Web Server

Luckily for us, this is an area where the propeller heads at IBM have implemented a really cool server on our IBM I operating system that makes this process so simple, it’s really quite astounding.

With a few clicks we can configure the integrated webserver and then use the the IWS* (Integrated Web Server) to share that information with the world wide web.

NOTE: the IWS happens to be the APACHE SERVER. But since this could change at some point in the future so I’m going to call the IWS rather than the Apache Server.

The IWS is easily used from any web browser that can talk to your IBM i Server and it has a very simple wizard that will create a webservice from your RPG program.

Not only that, but it will automagically create a WSDL*, and deploy the webservice to its application server. The IWS comes automatically with your IBM i System.

Your IWS is built with the PHP Language. PHP launched back in 94 as Personal Home Page  language, has evolved greatly over the last three decades. PHP has now been rebranded as "PHP: Hypertext Preprocessor" and is a server side scripting language that is embedded in the webserver HTML pages and us used to create dynamic content, access databases and build the entire smart websites under the covers. 

PHP offers terrific support for Web Services and SOAP/REST.

PHP services can call also call programs written in other languages such as Cobol or RPG and therefore PHP can be an alternative to the approach of the previous point.

PHP is very easy to understand and it's embedded within the HTML itself. 

Here is a very simple example of some PHP code embedded in HTML:

<html>
 <head>
   <title>Hello World</title> 
 </head>
  <body>
    <?php echo "Hello, World!";?>
 </body>
</html>

When you run this code in a web browser it gives you a very simple message in reply:

Hello, World!

You do not need to learn PHP to write webservices.

The nice thing about the IBM i Integrated Web Server you don't need to learn any new languages at all.

The IWS takes care of all of it for you.

DB2 Web Services

Your IBM i Website can natively access data from your database using native IBM i SQL for super fast response times, or other interfaces or by applications that use programming interfaces such as JDBC and SQLJ.

DB2 allows also to use Web services to query the database and to obtain the results as standard SOAP/REST messages.

Consuming Web Services from Cobol or RPG

There are lots of ways to do this and its much easier than you may think.

All we have to do is write a webserver program that does the business logic (for example, receive an order number parameter, read the order line details and return those parameters back).

If you want to access Cobol or RPG programs as Web Services, you can use the IBM Toolbox for Java or JTOpen to develop a Java Web Service which calls the Cobol or RPG program and return the results as a simple message string.

It allows to develop clients in Java or other languages to call legacy Cobol or RPG program and return the results as XML messages according to the Web services specifications.

You might be asking yourself

How do I write (an IBM-i program) RPG, to talk to the internet and receive or send parameters to a website or webservice?   For example, how can I receive an order number and return the order line information in XML?

Slow down - we will get there 🙂

All of these modules are going through all the basics so that, hopefully, the terminology clicks into place.

Let's recap to make sure you are on track

Jargon Recap

  • *What is the IWS? The integrated Web services server for IBM i enables the deployment of ILE-based program objects as Web services. The IWS is free and comes included with IBM i you simply need to start the server and start using it.
  • *What is a WSDL? A WSDL is an XML document that describes a web service. It actually stands for Web Services Description Language.
  • *What is a XML and JSON? Think of these as the language of the webservice. Webservices write their messages in JSON or XML so that the program (or browser) the other end can easily read what they are sending or receiving over the web.
  • *What is SOAP or REST? Don't panic. This is a trick question because we haven't covered this yet. Dive into the SOAP or REST lesson to find the answers.

Lets continue into the wonderful world of web services...

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}
>