Calling a Web Service from COBOL or CL

Anton Baclao picture Anton Baclao · Dec 17, 2012 · Viewed 7.8k times · Source

I'm using AS400 and I have been asked to call a web service from the green screen.

How can thisbe this achieved?

Any sample COBOL or CL code would be very helpful.

Answer

Benny Hill picture Benny Hill · Dec 17, 2012

I wrote some "middleware" in RPGLE to call a web service (SOAP) and process the XML data returned. Here's the process in a nutshell:

1) Open a socket to the web service
2) Build the XML "payload"
3) Transmit the SOAP request (wrap the payload in a SOAP body and transmit the whole through the socket opened in 1) and save the data sent back by the web service.
4) Parse the XML string returned to me (using the xml-sax BIF)
5) Process that data just like any other data.

I use a lot of stuff from Scott Klement (thank you very much Mr. Klement!):

ERRNO_H
IFS_H
IFSUTIL_H
SOCKET_H
SOCKUTIL_H

I also had to handle converting the data to/from EBCDIC and UTF-8. I think I modeled that process after something Scott wrote as well but I can't remember for sure. Search for iconv to get started on that.