Professional Documents
Culture Documents
Web Services
Web Services
M. L. Liu
we b s e rv ice
Th e we b
clie n t
(H TTP- ba s e d
we b s e rv ice
n e two rk )
we b s e rv ice
m e s s a g in g m e s s a g in g
tra n s po rt tra n s po rt
n e two rk n e two rk
W S D L ( W e b S e rv ice D e s cript io n L a n g u a g e )
s e rv ice de s cript io n
IP
n e two rk
m e th o d n a m e ,
p a r a m e te r l i s t we b
s e rvi ce we b
obje ct s e rv e r r e t u r n va l u e
clie n t
H TTP re qu e s t
H TTP re s po n s e
S O A P h e a de r
o p tion al
h e a de r block
h e a de r block
S O A P bo dy
req u ired
m e s s ag e bo dy
< -- H e a de rs g o h e re -->
< -- R e qu e s t g o e s h e re -->
<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>
returned value
<?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>
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>
<?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>
http://www.xmethods.com/gettingstarted/ap
ache.html
05/05/23 Distributed Computing, M. L. Liu 23
Apache SOAP installation
C:
s o ap % T O M C AT _ HO M E%
w eb ap p s
s o ap -2 _ 2
lib
s o ap s o ap .w ar
c las s es
o n jav a
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.*;
Found at http://www.xmethods.com
W eather - T emperature
Analyze W S D L | View RP C P rofile | http://w w w .xm ethods.net/sd/2001/T em peratureS ervic e.w sdl
X M ethods ID 8
S ervic e O w ner: xm ethods.net
Contac t Em ail: support@ xm ethods.net
S ervic e Hom e P age:
D esc ription: Current tem perature in a given U.S . zipc ode region.
S O AP Im plem entation: Apac he S O AP
M e th o d Na m e g e tTe m p
En dpo in t UR L h ttp://s e rv ice s .x m e th o ds .n e t :8 0 /s o a p/s e rv le t /rpcro u te r
S O A PA ctio n
M e th o d Na m e s pa ce UR I u rn :x m e th ods -Te m pe ra tu re
I n pu t Pa ra m e te rs zip c o d e s t rin g
http://www.onjava.com/pub/a/onjava/2002/02/27/t
omcat.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.
05/05/23 Distributed Computing, M. L. Liu 34
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
package onjava;
public class CalcService {
public int add(int p1, int p2) {
return p1 + p2;
}
return p1 - p2;
}
}
<isd:faultListener>org.apache.soap.server.DOMFaultList
ener</isd:faultListener>
</isd:service>
05/05/23 Distributed Computing, M. L. Liu 41
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.