You are on page 1of 47

TUG Seneca night school program

1
Web services and IBM i
Introduction to
Web services for RPG developers
Claus Weiss clausweiss22@gmail.com
TUG meeting March 2011
TUG Seneca night school program
2
Web services and IBM i
Acknowledgement
In parts of this presentation I am using work published b!
"inda #ole$ IBM #anada
Scott %lement$ %lement Sausage #o&$ Inc&
TUG Seneca night school program
3
Web services and IBM i
Agenda

Web ervices! What are the"# Wh" use


them#

$reating a Web ervice

Using RPG

Using %G&

$onsuming a 'eb service

Using Web ervice e(plorer

With %G&

With RPG using %G& or )TTP*PI


TUG Seneca night school
Based on IBM 'ational (eveloper for IBM i education material
)ublic
Web Service
*
#hange in the marketplace$ IBM i$ + App&(evelopment
The 1++0,s -e' Millennium
I&%! maller. reusable
programs
iSeries
Web Service
IBM i
$lient/erver
The 1+00,s
"arge$ monolithic
')G programs
AS,*--
Sstem ./0AS,*--
iSeries
IBM i
TUG Seneca night school program
5
Web services and IBM i
The )roblem! Integration
Integrating soft'are applications across multiple operating s"stems. programming languages. and
hard'are platforms is
(ifficult
1ot something that can be solved b an one particular proprietar environment
Traditionall". the problem has been one of tight1coupling

2ne application that calls a remote network is tied strongl to it b the function call it makes and the parameters
it re3uests

4i5ed interface to access remote programs or data$ with little fle5ibilit or adaptabilit to changing environments
or needs
What are Web services!

self6contained software components$

with well6defined interfaces 7WS("8$

that can be invoked over a network using


9M" and S2A) 7for message formats8
9M" Schema 7for data tpes8
:TT) 7for network transport8
WS(" 7to describe Web service interface8
This allo's applications to communicate
independent of

:ardware platforms

2perating sstems

)rogramming languages
TUG Seneca night school program
6
Web services and IBM i
Tpes of web services

S2A) imple 2b;ect *ccess Protocol

'e3uest is sent in S2A) document

'eturns a S2A) document

'<ST R%presentational tate Transfer

'e3uest is send in U'"

'eturns a 9M" or ;son= document

)29 Plain old 9M"

'e3uest is sent in 9M" document

'eturns a 9M" document


=>avaScript 2b;ect 1otation
TUG Seneca night school program
7
Web services and IBM i
Web Service

A Web Service is a special Web Application

A web application gets invoked b sending a re3uest from a browser

A web service is a program that gets invoked b sending a re3uest from


a program

The are both using the :TT),:TT)S protocol to receive re3uests


and return information to the re3uester&

Allowing to easil access the web service via the internet or intranet

?ou can sa a web service is a callable program that is accessible from


anwhere&
TUG Seneca night school program
8
Web services and IBM i
<volution of accessing programs 7services8
2)M
(namic calls onl
"imited interlanguage
calling
2)M ')G,#2B2",#"
#allable from ')G,#",#2B2" I"< programs
#all an other I"< program
I"<
Static and dnamic calls
full interlanguage calling
Modules and Serviceprograms
Internet,Intranet
Web Service
(namic invocation over the network
4ull interlanguage support
Web Service
An program
TUG Seneca night school program
9
Web services and IBM i
:ow does a S2A) Web Service work
Web
Service
re3uester
7consumer
client8
Send 'e3uest with document
describing the re3uest
and data
@soapenv!<nvelope 5mlns!soapenvABhttp!,,schemas&&&&&BC
@soapenv!:eader,C
@soapenv!BodC
@web!1umberTo(ollarsC
@web!d1umC -DE&-- @,web!d1umC
@,web!1umberTo(ollarsC
@,soapenv!BodC
@,soapenv!<nvelopeC &&&&&&&&
Send response back with document
including data
@soap!<nvelope 5mlns!soapABhttp!,,schemas&5mlsoap&org,soap,envelope,BC
@soap!BodC
@m!1umberTo(ollars'esponse 5mlns!mABhttp!,,www&dataaccess&com,webservicesserver,BC
@m!1umberTo(ollars'esultCninet five dollars@,m!1umberTo(ollars'esultC
@,m!1umberTo(ollars'esponseC
@,soap!BodC
@,soap!<nvelopeC
Web Service
1umberTo(ollars
TUG Seneca night school program
10
Web services and IBM i
S2A) message details

A protocol defining how the input,output data of a web service is sent

Send and receive data in 9M" documents

9M" (ocuments follow S2A) standard


@soapenv!<nvelope 5mlns!soapenvABhttp!,,schemas&5mlsoap&org,soap,envelope,B
5mlns!webABhttp!,,www&dataaccess&com,webservicesserver,BC
@soapenv!)eader,C
@soapenv!3od"C
@web!1umberTo(ollarsC
@web!d1umC -DE&-- @,web!d1umC
@,web!1umberTo(ollarsC
@,soapenv!BodC
@,soapenv!<nvelopeC
%(tra info! authentication. etc
2peration name!
4program/sub procedure/function name
and parameter data5
TUG Seneca night school program
11
Web services and IBM i
(ocumenting the Web Service

:ow do ou tell other people about our Web Service

Where is it located

What is the name

What input parameters does it e5cept

What output parameters does it return

?ou could create a document$ a web page etc

S2A) Web Services are described in a WS(" file

Web ervices (escription "anguage

9M" stle to describe a Web Service


TUG Seneca night school program
12
Web services and IBM i
WS(" details
<message name="NumberToDollarsSoapRequest">
<part name="parameters" element="tns:NumberToDollars"/>
</message>
<message name="NumberToDollarsSoapResponse">
<part name="parameters" element="tns:NumberToDollarsResponse"/>
</message>
<portType name="NumberConversionSoapType">
<operation name="NumberToDollars">
<documentation>Returns the non-zero dollar amount of the passed number.</documentation>
<input message="tns:NumberToDollarsSoapRequest"/>
<output message="tns:NumberToDollarsSoapResponse"/> </operation> </portType>
<binding>
Network protocol used in service </binding>
<service>
A grouping of services/ports (like service program containing multiple procedures)
</service> </definitions>
<definitions>
<types>
data types the service uses........ </types>
Messages sent and received b" service
2perations 4programs/procedures5 "ou can
use/call in service
:uman readable$ but more important tools can work with it easil
TUG Seneca night school program
13
Web services and IBM i
Terminolog used so far

Web Service

S2A)

WS("
U((I Universal (escription$ (iscover and Integration

'egistr standard for Service 2riented Architecture

A public repositor containing web service descriptions

U66I did not become accepted as the standard registr" for Web
ervices
TUG Seneca night school program
14
Web services and IBM i
U((I overview
#hart created b U((I 2ASIS Standard communit
TUG Seneca night school program
15
Web services and IBM i
Wh use a Web Service

Somebod else created something that ou want to use

Google services ver popular 7maps &&&&&&8

?ahoo for business information 7show me realtors for that postal code8

Simple conversion routines 7metric to &&&&&8

#urrenc e5change rates 7 (ollar to <uro8

Shipment tracking 7U)S$ 4ed<5 &&&&8

?our supplier implemented a web service 7orders status in3uir 8

?ou want to give our customers access to data 7parts on hand8

&&&&

Man man other web services that might come in hand


TUG Seneca night school program
16
Web services and IBM i
Web F&- application using Web Services
Sample application written in <G"
Web ervice to
calculate monthl"
pa"ment
7*)22 Web ervice to
sho' mortgage businesses
In the area
G22G&% Web ervice to
sho' locations on map
TUG Seneca night school program
17
Web services and IBM i
#reating and using a Web Service
1ow that ou have an understanding what a Web Service is and which pieces
make up a Web Service
"etGs look at

:ow to create a Web Service

:ow to use,consume a Web Service


TUG Seneca night school program
18
Web services and IBM i
Agenda

Web ervices! What are the"# Wh" use


them#

$reating a Web ervice

Using RPG

Using %G&

$onsuming a 'eb service

Using Web ervice %(plorer

With %G&

With RPG using %G& or )TTP*PI


TUG Seneca night school program
19
Web services and IBM i
Use ')G to create a Web Service
Write an ')G program or a sub procedure in a service program or use e5isting
Use a tool to create a wrapper around the ')G code

Wrapper will create


The 9M" definition to handle a re3uest that consumes our Web Service
The 9M" definition to send back the response from our Web Service
A WS(" file that describes our Web Service and its location
#ode to call the ')G program and pass the parameter values from the Web Service
re3uest
#ode to handle the return values from our ')G program and include them in the
response 9M" document

(eplo our Web Service wrapper to a server


TUG Seneca night school program
20
Web services and IBM i
RPG program 8ipervice
D ZIPSERVICE PR
D zipin 5a
D zipout 5a
D ZIPSERVICE PI
D zipin 5a
D zipout 5a
/Free
if zipin >= '90001' and zipin = '9!000'"
zipout = '0' "
e#$e"
zipout = '%1'"
endif"
&in#r = &on"
:ow it Works H #reating a Web Service with ')G
4irst! #reate program
Zip'ode in
Return (a#ue
0 or %1
TUG Seneca night school program
21
Web services and IBM i
)SD*
De$'ri+e$ $er(i'e
,nd $er(i'e
interfa'e$
')G program IipService
:ow it Works H #reating a Web Service with ')G
Second! #reate the Web Service Wrapper
E,R/),R -it. Ser(#et
/o 'a## RP0 pro1ra2
Webervice 'i8ard
Read RPG source
$reate 9M& for service
$reate :t;00 <ava servlet to call RPG
$reate Web application W*R file
6eplo" to Tomcat or W*
$reate W6&
Zip'ode in
Return (a#ue
0 or %1
TUG Seneca night school program
22
Web services and IBM i
*pp erver

)SD*
De$'ri+e$ $er(i'e
,nd $er(i'e
interfa'e$
')G program IipService
:ow it Works H #reating a Web Service with ')G
Test Web Service
),R -it. Ser(#et
/o 'a## RP0 pro1ra2
Web Service
e5plorer
'ead W(S"
#reate front end
to send re3uest
with data
(ispla response
Re3ue$t
-it. 45*
do'u2ent
'ontainin1
Zip'ode in
Re$pon$e -it. Return
(a#ue
Zip'ode in
Return
(a#ue
#all to ')G program
TUG Seneca night school program
23
Web services and IBM i
'un the ')G Web Service
Input to service
2utput from service
Web Service
TUG Seneca night school program
24
Web services and IBM i
#reating a Web Service using a EFE- Application
3270/5250
Business Logic
Database Access
RPG/COBOL
<5isting )rograms
Web 2=0
Web ervices
clients
Generate Web Services from HATS
and consume them with requests
and responses
)SD*
De$'ri+e$ $er(i'e
and $er(i'e
interfa'e$
)*T ervices
Wi8ard
Web ervice
Input fields on screens map to re3uest parameters
2utput fields on screens map to response data
TUG Seneca night school program
25
Web services and IBM i
Use <G" to create a Web Service
<nterprise Generation "anguage 7<G"8 111111> no' open source ???????
4ree download available JJJJJJJ
<G" contains a construct called a Service part

"ike a function,subprocedure
In the (eploment (escriptor ou tell the generator what kind of service to create
for the logic ou code in the Service part

S2A)$ '<ST$ or <G" service


TUG Seneca night school program
26
Web services and IBM i
Steps for #reating a Web Service with <G"

teps teps

#reate or use e5isting <G" pro;ect or <G" Web pro;ect

#reate a new service in <G"

Tell <G" what kind of service ou want to create 7deploment descriptor8

Use <G" to generate Web Service and WS("

6eplo" the Web ervice 6eplo" the Web ervice

Use the Web ervice 'i8ard to test the service Use the Web ervice 'i8ard to test the service
TUG Seneca night school program
27
Web services and IBM i
%G& program 8ipervice
$er(i'e ZipSer(i'e
fun'tion zipSer(i'efun'tion6zipin
$trin1 in7 zipout $trin1 out8
if 6zipin >= 9900019 :: zipin = 99!00098"
zipout = 909"
e#$e
zipout = 9=%19"
end
end
end
:ow it Works H #reating a Web Service with <G"
#reate program,service
#reate service dialog
Zip'ode in
Return (a#ue
0 or %1
TUG Seneca night school program
28
Web services and IBM i
)SD*
De$'ri+e$ $er(i'e
,nd $er(i'e
interfa'e$
<G" service IipService
:ow it Works H #reating a Web Service with <G"
#reate the Web Service
)e+ Ser(i'e
;a(a $er(#et
),R or E,R
Generate
Zip'ode in
Return (a#ue
0 or %1
%G& Web ervice generation

$reate 9M& for service
$reate <ava servlet
$reate Web application W*R/%*R file
6eplo" to Tomcat or W*
$reate W6&
TUG Seneca night school program
29
Web services and IBM i
)SD*
De$'ri+e$ $er(i'e
,nd $er(i'e
interfa'e$
:ow it Works H #reating a Web Service with <G"
Test Web Service
*pp erver

)e+ Ser(i'e
),R -it. Ser(#et
Web Service <5plorer
'ead W(S"
#reate front end
to send re3uest
with data
(ispla response
Re3ue$t
-it. 45*
do'u2ent
'ontainin1
Zip'ode in
Re$pon$e -it. Return
(a#ue
TUG Seneca night school program
30
Web services and IBM i
'un the <G" Web Service
Input to service
2utput from service
Web Service
TUG Seneca night school program
31
Web services and IBM i
#reating a Web Service

Use an" programming language

<ava. $. $@@ supported via *9I pro:ect

*9I provides functionalit" for creating


Web ervices 'rappers

$reates pro(is for Web ervice

7ou 'rite the logic. *9I provides the


Web ervices support

*pache open source pro:ect


2verview on the Apache A9IS Web )age
The well known Apache A5is$ and the second
generation of it$ the Apache A5isF$ are two Web Service
containers that help users to create$ deplo$ and run Web
Services&
TUG Seneca night school program
32
Web services and IBM i
Agenda

Web ervices! What are the"# Wh" use


them#

$reating a Web ervice

Using RPG

Using %G&

$onsuming a 'eb service

Using Web ervice %(plorer

With %G&

With RPG using %G& or )TTP*PI


TUG Seneca night school program
33
Web services and IBM i
#onsuming a Web Service using a tool,wiIard
Several tools on the web download and tr

S2A)UI ver popular


Use Web Service <5plorer$ part of 'B(

)oint <5plorer to WS("

<5tracts Input,2utput parameter$ invocation$ and U'I information

)rompts for input$ sends re3uest$ shows response


)SD*
De$'ri+e$
$er(i'e
,nd $er(i'e
interfa'e$
TUG Seneca night school program
34
Web services and IBM i
<G" consuming a service
E0* Ser(i'e$ -izard
)SD*
De$'ri+e$ $er(i'e
,nd $er(i'e
interfa'e$
%G& interface
interfa'e <u2+erCon(er$ionSoap/=pe>?@2#
>na2e=9<u2+erCon(er$ionSoap/=pe97 AA
fun'tion <u2+er/o)ord$6u+i<u2 de'i2a#6B18 in8
return$6$trin18>?@2# >na2e=9<u2+er/o)ord$9AA"
CDDD
Using <G" Web Service wiIard

Get service description from WS("

#reate interface 7like prototpe in ')G8 from it

Interface can be invoked like a function to consume Web Service


TUG Seneca night school program
35
Web services and IBM i
<G" consuming a service
Web 2=0
%G& interface
<u2+erCon(er$ionSoap/=pe
CDD
nu2Con( <u2+erCon(er$ionSoap/=pe>?EindSer(i'e >A A"
re$u#t = nu2Con(D<u2+er/o)ord$6nu2+erInput 8"
A==
Send re3uest to Web Service via Interface
Get response back from Web Service
*pp erver

)e+ Ser(i'e
),R -it. Ser(#et
TUG Seneca night school program
36
Web services and IBM i
')G consuming Web Service using >ava generated b <G"

teps

$reate %G& program consuming Web ervice

%nable propert". callable from native <ava

Generate <ava :ar

$op" :ar to I3M i

Write RPG program using <ava call capabilit" to


consume Web ervice

$ompile

Tr"
TUG Seneca night school program
37
Web services and IBM i
')G consuming Web Service using >ava generated b <G"
ILE business logic
rotot!pes to call
"ava
%G& logic
D* this is the constructor for the !"/#$%$ program &rapper
D ne&'&rap (R ) *T(R)+,*#$%$ - .programs.(rogramc/
D 01rapper. - *+)23TR4+T)R5
D*
D* call method for &rapper program ob6ect
D* 7 input parameters8 response &ill be in third parameter
D callmeth (R 9t(roc,*#$%$-
D .programs.(rogramc01rapper.-
D .call.5
D parm: 7;i ; <alue
D parm7 ) +lass,*#$%$-.6a<a.math.=igDecimal.5
D parm0 ) +lass,*#$%$-.6a<a.lang.3tring.5

Wrapper program
ProgramcBWrapper
2 input parms
1 response parm
Generated <ava program
sends reCuest to Web
ervice and gets
response
TUG Seneca night school program
38
Web services and IBM i
')G consuming Web Service using >ava generated b <G"
ILE business logic
call to "ava
wrapper
%G& logic
D mypgm: s o class,*#$%$-
D .programs.(rogramc01rapper.5
D response s >;a <arying
mypgm: = ne&'&rap,5?
// send re@uest to &eb ser<ice
callmeth,mypgm:- parm:- parm7 -parm05?
// response from 1eb 3er<ice is stored in parm0
// method getmyparm0 gets the response <alue
response = getbytes, getmyparm0,mypgm:55?
Wrapper program
ProgramcBWrapper
2 input parms
1 response parm
Generated <ava program
sends reCuest to Web
ervice and gets response
*pp erver

)e+ Ser(i'e
),R -it.
Ser(#et
TUG Seneca night school program
39
Web services and IBM i
Steps for consuming a Web Service using :TT)A)I

teps

6o'nload and restore )TTP*PI librar"

$reate 9M& for reCuest document in RPG


4sounds more difficult than it is5

Write RPG code to call )TTP*PI program

Write RPG sub procedure to get data


from response document

$ompile

Tr"
TUG Seneca night school program
40
Web services and IBM i
Use soapUI to e5tract 9M" document
$reate a pro:ect in soapUI

Use Web ervice W6&

soapUI e(tracts the 9M& for reCuest document

$op"/paste 9M& into RPG and edit 9M&

*ssign string to variable to pass to )TTP*PI


TUG Seneca night school program
41
Web services and IBM i
')G consuming Web Service using :TT)A)I
ILE business logic
3)$( = .<soapen<-n<elope /
9mlns-soapen<=Ahttp-//schemas.9mlsoap.org/soap/en<elope/A /
9mlns-&eb=Ahttp-//&&&.dataaccess.com/&ebser<icesser<er/A> /
<soapen<-Beader/> /
<soapen<-=ody> /
<&eb-2umberTo1ords> /
<&eb-ubi2um>. / pchar / .</&eb-ubi2um> /
</&eb-2umberTo1ords> /
</soapen<-=ody> /
</soapen<-n<elope> .?
The reCuest 9M& document
RPG Dariable 2*P gets document
pchar RPG variable contains data
TUG Seneca night school program
42
Web services and IBM i
')G consuming Web Service using :TT)A)I
ILE business logic
rotot!pes to use
HTTAI
D http'post'9ml...
D (R :;C ; *T(R)+,.BTT('4R"'()3T'*D".5
: D pe4R" 07EFE$ <arying const options,*<arsize5
7 D pe(ostData * <alue
0 D pe(ostData"en :;C ; <alue
G D pe3tart(roc * <alue procptr
> D pend(roc * <alue procptr
F D pe4srDta * <alue
E D peTimeout :;C ; <alue options,*nopass5
H D pe4ser$gent FG$ const options,*nopass-*omit5
I D pe+ontentType FG$ const options,*nopass-*omit5
:; D pe3)$($ction FG$ const options,*nopass-*omit5
)TTP*PI sends
9M& from RPG
$alls sub procedure
'ith Response
data
The protot"pe for httpEpostE(ml
TUG Seneca night school program
43
Web services and IBM i
')G consuming Web Service using :TT)A)I
ILE business logic
call to http#post#$ml
rc = http'post'9ml
, .http/

-//&&&.dataaccess.com/&ebser<icesser<er/numbercon<ersion.&so.
- Jaddr,3)$(5 / %$RKC2!D$T$)LL3T
- Jlen,3)$(5
- *24""
// (rocedure to in<oMe for response
- Jpaddr,Dap*mlData5
// <ariable &ith response <alue
- Jaddr,con<ersionres5
- BTT('TCD)4T
- BTT('43R$!2T
- .te9t/9ml? charset=4TL-H.
- .AA. 5?
httpEpostE(ml
ends reCuest
Gets response bacF
InvoFe httpapi
*pp
erver

)e+
Ser(i'e
TUG Seneca night school program
44
Web services and IBM i
')G consuming Web Service using :TT)A)I
ILE business logic
callbac% sub
procedure
( Dap*mlData =
D Dap*mlData (C
D result >7a <arying
D depth :;C ; <alue
D name :;7G$ <arying const
D path 7G>EF$ <arying const
D <alue F>>0>$ <arying const
D attrs * dim,07EFE5
D const options,*<arsize5
/free
if ,name = .m-2umberTo1ordsResult.5?
result =<alue?
endif?
)TTP*PI gets
response
document
$alls sub procedure
'ith Response
data
$allbacF sub procedure
Get this name from soapUI
TUG Seneca night school program
45
Web services and IBM i
Summar

RPG developers can

create Web ervices on I3M i

consume Web ervices on I3M i

$hoose from a variet" of tools

6epending on "our sFills

6epending on "our preferences


7es. "ou can do it
$ome to TUG night school and tr" it out
TUG Seneca night school program
46
Web services and IBM i
IBM #ommunit Sites for Business (evelopers
ibm=com/developer'orFs/rational/communit"/cafe/inde(=html
ibm=com/developer'orFs/rational/communit"/cafe/inde(=html
TUG Seneca night school program
47
Web services and IBM i