2. 01/30/15 Distributed Computing, M. L. Liu2
Sources of Information
Programming Web Services with SOAP, by Snell
et al, OâReilly
SOAP Tutorial,
http://www.w3schools.com/soap/default.asp
SoapRPC.com: Tutorials,
(http://www.soaprpc.com/tutorials/) A Busy
Developerâs Guide To Soap1.1
DaveNet : XML-RPC for Newbies,
http://davenet.userland.com/1998/07/14/xmlRpcForNew
SoapRPC.com: Other resources,
http://www.soaprpc.com/resources/
3. 01/30/15 Distributed Computing, M. L. Liu3
Web Services
Network services provided over HTTP â
âwired servicesâ
It is promoted as a new way to build
network applications from distributed
components that are language- and
platform-independent
The technologies are still evolving
We are more interested in the concept and
principles, but we will look into one API
(Apache SOAP).
4. 01/30/15 Distributed Computing, M. L. Liu4
Web Services
T h e w e b
( H T T P - b a s e d
n e t w o r k )
w e b s e r v i c e
w e b s e r v i c e
w e b s e r v i c e
c l i e n t
5. 01/30/15 Distributed Computing, M. L. Liu5
Web Service Software Components
A web service is a message-based network
service.
A server which provides a web service must
be capable of âsending and receiving
messages using some combination of
standard Internet protocolsâ
a p p l i c a t i o n
l o g i c
s e r v i c e
p r o x y
s e r v i c e
l i s t e n e r
s e r v i c e
r e q u e s t
6. 01/30/15 Distributed Computing, M. L. Liu6
Just-in-time integration
Network services can be integrated
dynamically, on an as-needed basis.
SunMicroâs jini is a framework that
supports the idea.
Network services are registered with a
service registry; a service consumer/client
looks up the registry to fulfill its needs.
The binding of a client to the service can
occur at runtime.
7. 01/30/15 Distributed Computing, M. L. Liu7
Web service protocol stack
t r a n s p o r t
n e t w o r k
m e s s a g i n g
s e r v i c e d e s c r i p t i o n
s e r v i c e d i s c o v e r y
t r a n s p o r t
n e t w o r k
m e s s a g i n g
s e r v i c e d e s c r i p t i o n
s e r v i c e d i s c o v e r y
a p p l i c a t i o n a p p l i c a t i o n
8. 01/30/15 Distributed Computing, M. L. Liu8
Web service protocols
t r a n s p o r t
n e t w o r k
m e s s a g i n g
s e r v i c e d e s c r i p t i o n
s e r v i c e d i s c o v e r y
a p p l i c a t i o n
U D D I ( U n i v e r s a l D e s c r i p t i o n , D i s c o v e r y ,
a n d I n t e g r a t i o n )
W S D L ( W e b S e r v i c e D e s c r i p t i o n L a n g u a g e )
X M L , S O A P ( S i m p l e O b je c t A c c e s s P r o t o c o l )
T C P , H T T P , S M T P , J a b b e r
I P
9. 01/30/15 Distributed Computing, M. L. Liu9
SOAP
SOAP is a protocol which applies XML for
message exchange in support of remote
method calls over the Internet.
Compared to remote method invocation or
CORBA-based facilities:
â SOAP is web-based or âwiredâ and hence is not
subject to firewall restrictions
â Language-independent
â Can provide just-in-time service integration
10. 01/30/15 Distributed Computing, M. L. Liu10
Remote Procedure Call using HTTP
w e b
s e r v e r
w e b
c l i e n t
s e r v i c e
o b j e c t
H T T P r e q u e s t
H T T P r e s p o n s e
m e t h o d n a m e ,
p a r a m e t e r l i s t
r e t u r n v a l u e
11. 01/30/15 Distributed Computing, M. L. Liu11
SOAP Messages
m e s s a g e b o d y
S O A P b o d y
h e a d e r b l o c k
h e a d e r b l o c k
S O A P h e a d e r
S O A P e n v e l o p e
optionalrequired
12. 01/30/15 Distributed Computing, M. L. Liu12
An XML-encoded SOAP RPC
< s o a p : E n v e l o p e x m l n s : s o a p = ' h t t p : / / w w w . w 3 . o r g / 2 0 0 1 / 1 0 / s o a p - e n v e l o p e ' >
< s o a p : H e a d e r >
< - - H e a d e r s g o h e r e - - >
< / s o a p : H e a d e r >
< s o a p : B o d y >
< - - R e q u e s t g o e s h e r e - - >
< / s o a p : B o d y >
< / s o a p : E n v e l o p e >
S o u r c e : h t t p : / / w w w . x m l . c o m /
13. 01/30/15 Distributed Computing, M. L. Liu13
Example of a SOAP message
< s o a p : E n v e l o p e x m l n s : s o a p = ' h t t p : / / w w w . w 3 . o r g / 2 0 0 1 / 1 0 / s o a p - e n v e l o p e ' >
< s o a p : H e a d e r >
< h : L o g x m l n s : h = ' h t t p : / / e x a m p l e . o r g / c v s / l o g g i n g ' >
< t r a c e > 4 < / t r a c e >
< / h : L o g >
< h : P S e r v e r x m l n s : h = ' h t t p : / / e x a m p l e . o r g / c v s / p s e r v e r '
s o a p : m u s t U n d e r s t a n d = ' t r u e ' >
< u s e r n a m e > a n o n c v s @ e x a m p l e . o r g < / u s e r n a m e >
< p a s s w o r d > a n o n c v s < / p a s s w o r d >
< / h : P S e r v e r >
< / s o a p : H e a d e r >
< s o a p : B o d y >
< m : C h e c k o u t x m l n s : m = ' h t t p : / / e x a m p l e . o r g / c v s ' >
< s o u r c e > / x m l / s o a p / w e b s e r v i c e s / c v s < / s o u r c e >
< r e v i s i o n > 1 . 1 < / r e v i s i o n >
< d e s t i n a t i o n > / e t c / u s r / m a r t i n g / s o u r c e / x m l < / d e s t i n a t i o n >
< / m : C h e c k o u t >
< / s o a p : B o d y >
< / s o a p : E n v e l o p e >
s o u r c e : h t t p : / / w w w . x m l . c o m
14. 01/30/15 Distributed Computing, M. L. Liu14
A SOAP Message that contains a remote
procedure call
source: (http://www.soaprpc.com/tutorials/) A Busy Developerâs Guide To Soap1.1
<SOAP-ENV:Envelope
SOAP-ENV:encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
<SOAP-ENV:Body>
<m:getStateName xmlns:m="http://www.soapware.org/">
<statenum xsi:type="xsd:int">41</statenum>
</m:getStateName>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
15. 01/30/15 Distributed Computing, M. L. Liu15
An Example SOAP Request
source: (http://www.soaprpc.com/tutorials/) A Busy Developerâs Guide To Soap1.1
< ? x m l v e r s io n = " 1 .0 " ? >
< S O A P - E N V : E n v e lo p e S O A P - E N V : e n c o d in g S t y le = " h t t p : //s c h e m a s .x m ls o a p .o r g /s o a p /e n c o d in g /"
x m ln s : S O A P - E N C = " h t t p : //s c h e m a s .x m ls o a p .o r g /s o a p /e n c o d in g /"
x m ln s : S O A P - E N V = " h t t p : //s c h e m a s .x m ls o a p .o r g /s o a p /e n v e lo p e /"
x m ln s : x s d = " h t t p : //w w w .w 3 .o r g /1 9 9 9 /X M L S c h e m a "
x m ln s : x s i= " h t t p : //w w w .w 3 .o r g /1 9 9 9 /X M L S c h e m a - in s t a n c e " >
< S O A P - E N V : B o d y >
< m : g e t S t a t e N a m e x m ln s : m = " h t t p : //w w w .s o a p w a r e .o r g /" >
< s t a t e n u m x s i: t y p e = " x s d : in t " > 4 1 < /s t a t e n u m >
< /m : g e t S t a t e N a m e >
< /S O A P - E N V : B o d y >
< /S O A P - E N V : E n v e lo p e >
p a r a m e t e r o f t y p e in t a n d v a lu e 4 1
p r o c e d u r e
n a m e
n a m e o f s e r v e r
16. 01/30/15 Distributed Computing, M. L. Liu16
Response example
source: (http://www.soaprpc.com/tutorials/) A Busy Developerâs Guide To Soap1.1
< ? x m l v e r s io n = " 1 .0 " ? >
< S O A P -E N V :E n v e lo p e S O A P -E N V :
e n c o d in g S ty le = " h ttp ://s c h e m a s .x m ls o a p .o r g /s o a p /e n c o d in g /"
x m ln s :S O A P -E N C = " h ttp ://s c h e m a s .x m ls o a p .o r g /s o a p /e n c o d in g /"
x m ln s :S O A P -E N V = " h ttp ://s c h e m a s .x m ls o a p .o r g /s o a p /e n v e lo p e /"
x m ln s :x s d = " h ttp ://w w w .w 3 .o r g /1 9 9 9 /X M L S c h e m a "
x m ln s :x s i= " h ttp ://w w w .w 3 .o r g /1 9 9 9 /X M L S c h e m a -in s ta n c e " >
< S O A P - E N V :B o d y >
< m :g e tS ta te N a m e R e s p o n s e x m ln s :m = " h ttp ://w w w .s o a p w a r e .o r g /" >
< R e s u lt x s i:ty p e = " x s d :s tr in g " > S o u th D a k o ta < /R e s u lt>
< /m :g e tS ta te N a m e R e s p o n s e >
< /S O A P - E N V :B o d y >
< /S O A P -E N V :E n v e lo p e >
n a m e o f s e r v e r
re tu r n e d v a lu e
p r o c e d u r e n a m e
17. 01/30/15 Distributed Computing, M. L. Liu17
Example of a SOAP message for
an error RPC response
source: (http://www.soaprpc.com/tutorials/) A Busy Developerâs Guide To Soap1.1
< ? x m l v e r s i o n = " 1 . 0 " ? >
< S O A P - E N V : E n v e l o p e S O A P - E N V :
e n c o d i n g S t y l e = " h t t p : / / s c h e m a s . x m l s o a p . o r g / s o a p / e n c o d i n g / "
x m l n s : S O A P - E N V = " h t t p : / / s c h e m a s . x m l s o a p . o r g / s o a p / e n v e l o p e / "
x m l n s : x s d = " h t t p : / / w w w . w 3 . o r g / 1 9 9 9 / X M L S c h e m a "
x m l n s : x s i = " h t t p : / / w w w . w 3 . o r g / 1 9 9 9 / X M L S c h e m a - i n s t a n c e " >
< S O A P - E N V : B o d y >
< S O A P - E N V : F a u l t >
< f a u l t c o d e > S O A P - E N V : C l i e n t < / f a u l t c o d e >
< f a u l t s t r i n g >
C a n ' t c a l l g e t S t a t e N a m e b e c a u s e t h e r e a r e
t o o m a n y p a r a m e t e r s .
< / f a u l t s t r i n g >
< / S O A P - E N V : F a u l t >
< / S O A P - E N V : B o d y >
< / S O A P - E N V : E n v e l o p e >
18. 01/30/15 Distributed Computing, M. L. Liu18
HTTP and SOAP RPC Request
source: (http://www.soaprpc.com/tutorials/) A Busy Developerâs Guide To Soap1.1
A SOAP message can be used to transport a
SOAP remote procedure request/response, as
follows:
POST /examples HTTP/1.1
User-Agent: Radio UserLand/7.0 (WinNT)
Host: localhost:81
Content-Type: text/xml; charset=utf-8
Content-length: 474
SOAPAction: "/examples"
<blank line>
<text for SOAP message>
19. 01/30/15 Distributed Computing, M. L. Liu19
An HTTP request that carries a SOAP RPC request
source: (http://www.soaprpc.com/tutorials/) A Busy Developerâs Guide To Soap1.1
POST /examples HTTP/1.1
User-Agent: Radio UserLand/7.0 (WinNT)
Host: localhost:81
Content-Type: text/xml; charset=utf-8
Content-length: 474
SOAPAction: "/examples"
<?xml version="1.0"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle=
"http://schemas.xmlsoap.org/soap/encoding/" xmlns:
SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:
SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
<SOAP-ENV:Body>
<m:getStateName xmlns:m="http://www.soapware.org/">
<statenum xsi:type="xsd:int">41</statenum>
</m:getStateName>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
20. 01/30/15 Distributed Computing, M. L. Liu20
An HTTP request that carries a SOAP RPC response
source: (http://www.soaprpc.com/tutorials/) A Busy Developerâs Guide To Soap1.1
HTTP/1.1 200 OK
Connection: close
Content-Length: 499
Content-Type: text/xml; charset=utf-8
Date: Wed, 28 Mar 2001 05:05:04 GMT
Server: UserLand Frontier/7.0-WinNT
<?xml version="1.0"?>
<SOAP-ENV:Envelope SOAP-
ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
<SOAP-ENV:Body>
<m:getStateNameResponse xmlns:m="http://www.soapware.org/">
<Result xsi:type="xsd:string">South Dakota</Result>
</m:getStateNameResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
21. 01/30/15 Distributed Computing, M. L. Liu21
Error Example
source: (http://www.soaprpc.com/tutorials/) A Busy Developerâs Guide To Soap1.1
HTTP/1.1 500 Server Error
Connection: close
Content-Length: 511
Content-Type: text/xml; charset=utf-8
Date: Wed, 28 Mar 2001 05:06:32 GMT
Server: UserLand Frontier/7.0-WinNT
<?xml version="1.0"?>
<SOAP-ENV:Envelope SOAP-
ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/1999/XMLSchema"
xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance">
<SOAP-ENV:Body>
<SOAP-ENV:Fault>
<faultcode>SOAP-ENV:Client</faultcode>
<faultstring>Can't call getStateName because there are too many
parameters.</faultstring>
</SOAP-ENV:Fault>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
22. 01/30/15 Distributed Computing, M. L. Liu22
SOAP Packages
source: http://www.soapuser.com
Apache SOAP for Java
Apache Axis for Java
Idoox WASP for C++
Microsoft SOAP Toolkit (part of the .net
framework)
SOAP::Lite for Perl
23. 01/30/15 Distributed Computing, M. L. Liu23
Apache SOAP
Allows clients and services to be written in
Java
Part of the Apache-XML project (
http://xml.apache.org/)
SOAP package downloadable:
http://xml.apache.org/dist/soap/
Installation instruction:
http://www.xmethods.com/gettingstarted/apache.h
24. 01/30/15 Distributed Computing, M. L. Liu24
Apache SOAP installation
% T O M C A T _ H O M E %
w e b a p p s
s o a p
W E B - I N F
c la s s e s
o n ja v a
C a lc S e r v ic e . ja v a
C a lc S e r v ic e . c la s s
D e p lo y m e n t D e s c r ip t o r . x m l
s o a p . w a r
s o a p
C :
s o a p - 2 _ 2
lib
x e r c e s , ja r m a il. ja r s o a p . ja r a c t iv a t io n . ja r
25. 01/30/15 Distributed Computing, M. L. Liu25
Classpath setting
set CLASSPATH=
C:soapsoap-2_2libxerces.jar;
C:jdk1.3bin;
C:jdk1.3libtools.jar;
C:soapsoap-2_2libmail.jar;
C:soapsoap-2_2libsoap.jar;
C:soapsoap-2_2libactivation.jar;
C:tomcatlibservlet.jar;
.;
26. 01/30/15 Distributed Computing, M. L. Liu26
Writing a Client Application using Apache SOAP
source: http://www.xmethods.com/gettingstarted/apache.html
Classpath
Your CLASSPATH environment variable should have
both the "soap.jar" and "xerces.jar" JAR files included.
Importing packages
For basic SOAP method invocation, you should import the
following at minimum:
// Required due to use of URL class , required by Call class
import java.net.*;
// Required due to use of Vector class
import java.util.*;
// Apache SOAP classes used by client
import org.apache.soap.util.xml.*;
import org.apache.soap.*;
import org.apache.soap.rpc.*;
27. 01/30/15 Distributed Computing, M. L. Liu27
Ready-made SOAP Services
A number of SOAP ready-made services are
available at http://www.xmethods.com/
XMethods Service Weather Temperature
ID8
Service Owner:xmethods.net
Contact Email:support@xmethods.net
Service Description:Current temperature in a
given U.S. zipcode region.
SOAP Implementation:Apache SOAP
28. 01/30/15 Distributed Computing, M. L. Liu28
Sample SOAP service
A n a ly z e W S D L | V ie w R P C P r o f ile | h ttp ://w w w .x m e th o d s .n e t/s d /2 0 0 1 /T e m p e r a tu r e S e r v ic e .w s d l
X M e th o d s I D 8
S e r v ic e O w n e r : x m e th o d s .n e t
C o n ta c t E m a il: s u p p o r t@ x m e th o d s .n e t
S e r v ic e H o m e P a g e :
D e s c r ip tio n : C u r r e n t te m p e r a tu r e in a g iv e n U .S . z ip c o d e r e g io n .
S O A P I m p le m e n ta tio n : A p a c h e S O A P
W e a th e r - T e m p e ra tu re
Found at http://www.xmethods.com
29. 01/30/15 Distributed Computing, M. L. Liu29
RPC Profile for Service
R P C P r o f i l e f o r S e r v i c e " W e a t h e r - T e m p e r a t u r e "
M e t h o d N a m e g e t T e m p
E n d p o i n t U R L h t t p : / / s e r v i c e s . x m e t h o d s . n e t : 8 0 / s o a p / s e r v l e t / r p c r o u t e r
S O A P A c t i o n
M e t h o d N a m e s p a c e U R I u r n : x m e t h o d s - T e m p e r a t u r e
I n p u t P a r a m e t e r s z ip c o d e s t r i n g
O u t p u t P a r a m e t e r s r e t u r n f l o a t
See sample: TempClient.java
30. 01/30/15 Distributed Computing, M. L. Liu30
Client program samples
See samples in client folder:
â TempClient.java
â StockQuoteClient.java
â CurrencyClient.java
31. 01/30/15 Distributed Computing, M. L. Liu31
SOAP data types
SOAP Data Types,
http://www.sdc.iup.edu/outreach/spring2002/web
Uses XML Schema data types
Primitive Types
string, boolean, decimal, float, double,
duration, dateTime, time, date,
gYearMonth, gYear, gMonthDay, gDay,
gMonth, hexBinary, base64Binary, anyURI,
QName, NOTATION
32. 01/30/15 Distributed Computing, M. L. Liu32
SOAP data types
Derived Types
Simple types (derived from a single primitive
type)
* integer is derived from decimal
* int (-2147483648 <= int <= 2147483647) is
derived from long which is derived from integer
* 5-digit zip code can be derived from int
* may use regular expressions to specify derived
types, such as ([A-Z]){2,3}-d{5}
33. 01/30/15 Distributed Computing, M. L. Liu33
Complex Type
Complex types (struct or array)
Struct example
<instructor>
<firstname xsi:type="xsd:string">Ed</firstname>
<lastname xsi:type="xsd:string">Donley</lastname>
</instructor>
Array example
<mathcourses xsi:type=
"SOAP-ENC:Array" SOAP
ENC:arrayType="se:string[3]">
<se:string>10452C</se:string>
<se:string>10454C</se:string>
<se:string>11123T</se:string>
</mathcourses>
34. 01/30/15 Distributed Computing, M. L. Liu34
Creating Web Services (server-side
SOAP)
O'Reilly Network: Using SOAP with Tomcat [Feb. 27,
http://www.onjava.com/pub/a/onjava/2002/02/2
7/tomcat.htm
Apache SOAP allows you to create and deploy a
SOAP web service.
You must install some .jar files on your system
and set the CLASSPATH to them:
Algorithm:
1. Write a class for providing the service.
2. Create a deployment descriptor in XML.
3. Deploy the service with the service manager.
35. 01/30/15 Distributed Computing, M. L. Liu35
The Apache SOAP service
manager
The service manager is itself implemented as a SOAP
service.
To see what services are deployed on your system:
java org.apache.soap.server.ServiceManagerClient
http://localhost:8080/soap/servlet/rpcrouter list
To deploy a service:
java org.apache.soap.server.ServiceManagerClient
http://localhost:8080/soap/servlet/rpcrouter deploy
foo.xml
36. 01/30/15 Distributed Computing, M. L. Liu36
Creating a SOAP Service
O'Reilly Network: Using SOAP with Tomcat [Feb. 27, 2002]
http://www.onjava.com/pub/a/onjava/2002/02/27/tomcat.html
A SOAP service can be just about any Java
class that exposes public methods for
invocation. The class does not need to know
anything about SOAP, or even that it is
being executed as a SOAP service.
The method parameters of a SOAP service
must be serializable. The available types
that can be used as SOAP service
parameters are shown in (Listing 2) (shown
on next slide)
37. 01/30/15 Distributed Computing, M. L. Liu37
SOAP Service Parameter Types
All Java primitive types and their corresponding
wrapper classes
Java arrays
java.lang.String
java.util.Date
java.util.GregorianCalendar
java.util.Vector
java.util.Hashtable
java.util.Map
38. 01/30/15 Distributed Computing, M. L. Liu38
SOAP Service Parameter Types
java.math.BigDecimal
javax.mail.internet.MimeBodyPart
java.io.InputStream
javax.activation.DataSource
javax.activation.DataHandler
org.apache.soap.util.xml.QName
org.apache.soap.rpc.Parameter
java.lang.Object (must be a JavaBean)
39. 01/30/15 Distributed Computing, M. L. Liu39
Sample SOAP Service Implementations
See sample in SOAP folder:
TempService: A temperature service
Exchange: currency exchange service and
client
40. 01/30/15 Distributed Computing, M. L. Liu40
Sample SOAP Service Class
// A sample SOAP service class
// source: http://www.onjava.com/pub/a/onjava/2002/02/27/tomcat.html
package onjava;
public class CalcService {
public int add(int p1, int p2) {
return p1 + p2;
}
public int subtract(int p1, int p2) {
return p1 - p2;
}
}
42. 01/30/15 Distributed Computing, M. L. Liu42
Summary
SOAP is a protocol that makes use of HTTP
requests and responses to effect remote method
calls to web services.
A SOAP method call is encoded in XML and is
embedded in an HTTP request
The return value of a method call is likewise
embedded and encoded in an HTTP response
A number of SOAP APIs are available for
programming web services and client method
calls. The Apache API was introduced.