Web services
-
Upload
lopjuan -
Category
Technology
-
view
1.433 -
download
2
description
Transcript of Web services
04/10/23 Distributed Computing, M. L. Liu 1
Web Services
M. L. Liu
04/10/23 Distributed Computing, M. L. Liu 2
Sources of InformationProgramming Web Services with SOAP, by Snell et al, O’ReillySOAP Tutorial, http://www.w3schools.com/soap/default.aspSoapRPC.com: Tutorials, (http://www.soaprpc.com/tutorials/) A Busy Developer’s Guide To Soap1.1DaveNet : XML-RPC for Newbies, http://davenet.userland.com/1998/07/14/xmlRpcForNewbiesSoapRPC.com: Other resources, http://www.soaprpc.com/resources/
04/10/23 Distributed Computing, M. L. Liu 3
Web ServicesNetwork 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-independentThe technologies are still evolvingWe are more interested in the concept and principles, but we will look into one API (Apache SOAP).
04/10/23 Distributed Computing, M. L. Liu 4
Web Services
Th e we b(H TTP-ba s e d
n e two rk )
we b s e rv ice
we b s e rv ice
we b s e rv ice
clie n t
04/10/23 Distributed Computing, M. L. Liu 5
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 pplica t io nlo g ic
s e rv icepro x y
s e rv icelis t e n e r
s e rv icere qu e s t
04/10/23 Distributed Computing, M. L. Liu 6
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.
04/10/23 Distributed Computing, M. L. Liu 7
Web service protocol stack
t ra n s po rt
n e two rk
m e s s a g in g
s e rv ice de s cript io n
s e rv ice dis co v e ry
tra n s po rt
n e two rk
m e s s a g in g
s e rv ice de s cript io n
s e rv ice dis co v e ry
a pplica t io n a pplica t io n
04/10/23 Distributed Computing, M. L. Liu 8
Web service protocols
t ra n s po rt
n e two rk
m e s s a g in g
s e rv ice de s cript io n
s e rv ice dis co v e ry
a pplica t io n
UD D I (Un iv e rs a l D e s cript io n , D is co v e ry , a n d I n te g ra t io n )
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 )
X M L , S O A P (S im ple O bje ct A cce s s Pro to co l)
TC P, H TTP, S M TP, J a bbe r
I P
04/10/23 Distributed Computing, M. L. Liu 9
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
04/10/23 Distributed Computing, M. L. Liu 10
Remote Procedure Call using HTTP
we bs e rv e r
we bclie n t
s e rvi ceobje ct
H TTP re qu e s t
H TTP re s po 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 va l u e
04/10/23 Distributed Computing, M. L. Liu 11
SOAP Messages
m e s s a g e bo dy
S O A P bo dy
h e a de r blo ck
h e a de r blo ck
S O A P h e a de r
S O A P e n v e lo pe
opti
onal
req
uir
ed
04/10/23 Distributed Computing, M. L. Liu 12
An XML-encoded SOAP RPC
< s o a p:En v e lo pe x m ln s : s o a p= 'h t tp: //www.w3 .o rg /2 0 0 1 /1 0 /s o a p-e n v e lo pe '> < s o a p:H e a de r>
< - - H e a de rs g o h e re - ->
< /s o a p:H e a de r> < s o a p:B o dy >
< - - R e qu e s t g o e s h e re - ->
< /s o a p:B o dy >< /s o a p:En v e lo pe >
S o u rce : h t tp: //www.x m l.co m /
04/10/23 Distributed Computing, M. L. Liu 13
Example of a SOAP message
< s o a p:En v e lo pe x m ln s : s o a p= 'h t tp: //www.w3 .o rg /2 0 0 1 /1 0 /s o a p-e n v e lo pe '>< s o a p:H e a de r>
< h :L o g x m ln s :h = 'h t tp: //e x a m ple .o rg /cv s /lo g g in g '> < tra ce > 4 < /tra ce > < /h :L o g > < h : PS e rv e r x m ln s :h = 'h t tp: //e x a m ple .o rg /cv s /ps e rv e r' s o a p: m u s tUn de rs ta n d= 'tru e ' > < u s e rn a m e > a n o n cv s @ e x a m ple .o rg < /u s e rn a m e > < pa s s wo rd> a n o n cv s < /pa s s wo rd> < /h : PS e rv e r> < /s o a p:H e a de r>
< s o a p:B o dy > < m :C h e ck o u t x m ln s :m = 'h t tp: //e x a m ple .o rg /cv s '> < s o u rce > /x m l/s o a p/we bs e rv ice s /cv s < /s o u rce > < re v is io n > 1 .1 < /re v is io n > < de s t in a t io n > /e tc/u s r/m a rt in g /s o u rce /x m l< /de s t in a t io n > < /m :C h e ck o u t> < /s o a p:B o dy >< /s o a p:En v e lo pe >
s o u rce : h t tp: //www.x m l.co m
04/10/23 Distributed Computing, M. L. Liu 14
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>
04/10/23 Distributed Computing, M. L. Liu 15
An Example SOAP Requestsource: (http://www.soaprpc.com/tutorials/) A Busy Developer’s Guide To Soap1.1
< ? x m l v e rs io n = " 1 .0 " ? >< S O A P-ENV :En v e lo pe S O A P- ENV :e n co din g S ty le = " h t tp: //s ch e m a s .x m ls o a p.o rg /s o a p/e n co din g /"x m ln s :S O A P- ENC = " h t tp: //s ch e m a s .x m ls o a p.o rg /s o a p/e n co din g /"x m ln s :S O A P- ENV = " h t tp: //s ch e m a s .x m ls o a p.o rg /s o a p/e n v e lo pe /"x m ln s :x s d= " h t tp: //www.w3 .o rg /1 9 9 9 /X M L S ch e m a "x m ln s :x s i= " h t tp: //www.w3 .o rg /1 9 9 9 /X M L S ch e m a - in s ta n ce " >
< S O A P- ENV :B o dy > < m :g e tS ta te Na m e x m ln s :m = " h t tp: //www.s o a pwa re .o rg /" > < s ta te n u m x s i: ty pe = " x s d: in t" > 4 1 < /s ta te n u m > < /m :g e tS ta te Na m e > < /S O A P- ENV :B o dy > < /S O A P- ENV :En v e lo pe >
pa ra m e te r o f ty pe in t a n d v a lu e 4 1
pro ce du ren a m e
n a m e o f s e rv e r
04/10/23 Distributed Computing, M. L. Liu 16
Response example source: (http://www.soaprpc.com/tutorials/) A Busy Developer’s Guide To Soap1.1
< ? x m l v e rs io n = " 1 .0 " ? >< S O A P- ENV :En v e lo pe S O A P- ENV :
e n co din g S ty le = " h t tp: //s ch e m a s .x m ls o a p.o rg /s o a p/e n co din g /"x m ln s :S O A P- ENC = " h t tp: //s ch e m a s .x m ls o a p.o rg /s o a p/e n co din g /"x m ln s :S O A P- ENV = " h t tp: //s ch e m a s .x m ls o a p.o rg /s o a p/e n v e lo pe /"x m ln s :x s d= " h t tp: //www.w3 .o rg /1 9 9 9 /X M L S ch e m a "x m ln s :x s i= " h t tp: //www.w3 .o rg /1 9 9 9 /X M L S ch e m a - in s ta n ce " >
< S O A P- ENV :B o dy > < m :g e tS ta te Na m e R e s po n s e x m ln s :m = " h t tp: //www.s o a pwa re .o rg /" > < R e s u lt x s i: ty pe = " x s d:s trin g " > S o u th D a k o ta < /R e s u lt> < /m :g e tS ta te Na m e R e s po n s e > < /S O A P- ENV :B o dy >< /S O A P- ENV :En v e lo pe >
n a m e o f s e rv e r
r e tu r n ed v a lu e
pro ce du re n a m e
04/10/23 Distributed Computing, M. L. Liu 17
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 rs io n = " 1 .0 " ? >< S O A P-ENV :En v e lo pe S O A P- ENV :
e n co din g S ty le = " h t tp: //s ch e m a s .x m ls o a p.o rg /s o a p/e n co din g /"x m ln s :S O A P-ENV = " h t tp: //s ch e m a s .x m ls o a p.o rg /s o a p/e n v e lo pe /"x m ln s :x s d= " h t tp: //www.w3 .o rg /1 9 9 9 /X M L S ch e m a "x m ln s :x s i= " h t tp: //www.w3 .o rg /1 9 9 9 /X M L S ch e m a - in s ta n ce " >
< S O A P- ENV :B o dy > < S O A P- ENV :Fa u lt> < fa u lt co de > S O A P- ENV :C lie n t< /fa u lt co de > < fa u lt s t rin g > C a n 't ca ll g e tS ta te Na m e be ca u s e th e re a re t o o m a n y pa ra m e te rs . < /fa u lt s t rin g > < /S O A P- ENV :Fa u lt> < /S O A P- ENV :B o dy >< /S O A P- ENV :En v e lo pe >
04/10/23 Distributed Computing, M. L. Liu 18
HTTP and SOAP RPC Requestsource: (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:81Content-Type: text/xml; charset=utf-8Content-length: 474SOAPAction: "/examples"<blank line>
<text for SOAP message>
04/10/23 Distributed Computing, M. L. Liu 19
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.1User-Agent: Radio UserLand/7.0 (WinNT)Host: localhost:81Content-Type: text/xml; charset=utf-8Content-length: 474SOAPAction: "/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>
04/10/23 Distributed Computing, M. L. Liu 20
An HTTP request that carries a SOAP RPC responsesource: (http://www.soaprpc.com/tutorials/) A Busy Developer’s Guide To Soap1.1
HTTP/1.1 200 OKConnection: closeContent-Length: 499Content-Type: text/xml; charset=utf-8Date: Wed, 28 Mar 2001 05:05:04 GMTServer: 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>
04/10/23 Distributed Computing, M. L. Liu 21
Error Examplesource: (http://www.soaprpc.com/tutorials/) A Busy Developer’s Guide To Soap1.1
HTTP/1.1 500 Server ErrorConnection: closeContent-Length: 511Content-Type: text/xml; charset=utf-8Date: Wed, 28 Mar 2001 05:06:32 GMTServer: 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>
04/10/23 Distributed Computing, M. L. Liu 22
SOAP Packagessource: 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
04/10/23 Distributed Computing, M. L. Liu 23
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.html
04/10/23 Distributed Computing, M. L. Liu 24
Apache SOAP installation
% T O M C AT _ HO M E %
w eb ap p s
s o ap
W E B- I N F
c las s es
o n jav a
C alc S er v ic e . jav aC alc S er v ic e . c las sD ep lo y m en tD es c r ip to r .x m l
s o ap .w ar
s o ap
C :
s o ap - 2 _ 2
lib
x er c es , ja r m ail. ja r s o ap . ja r ac tiv a tio n . ja r
04/10/23 Distributed Computing, M. L. Liu 25
Classpath setting
set CLASSPATH=C:\soap\soap-2_2\lib\xerces.jar;
C:\jdk1.3\bin;
C:\jdk1.3\lib\tools.jar;
C:\soap\soap-2_2\lib\mail.jar;
C:\soap\soap-2_2\lib\soap.jar;
C:\soap\soap-2_2\lib\activation.jar;
C:\tomcat\lib\servlet.jar;
.;
04/10/23 Distributed Computing, M. L. Liu 26
Writing a Client Application using Apache SOAPsource: 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.*;
04/10/23 Distributed Computing, M. L. Liu 27
Ready-made SOAP ServicesA number of SOAP ready-made services are available at http://www.xmethods.com/
XMethods Service Weather Temperature
ID8
Service Owner:xmethods.net
Contact Email:[email protected]
Service Description:Current temperature in a given U.S. zipcode region.
SOAP Implementation:Apache SOAP
04/10/23 Distributed Computing, M. L. Liu 28
Sample SOAP service
An aly ze W S D L | View R P C P r o f ile | h t tp :/ /w w w .x m eth o d s .n e t /s d /2 0 0 1 /T em p era tu r eS erv ic e .w s d lX M eth o d s I D 8S er v ic e O w n er : x m eth o d s .n e tC o n tac t Em ail: s u p p o r t@ x m eth o d s .n e tS er v ic e Ho m e P ag e:D es c r ip tio n : C u r r en t tem p era tu r e in a g iv en U.S . z ip c o d e r eg io n .S O AP Im p lem en ta tio n : Ap ac h e S O AP
W e a the r - T e m p e ra tu re
Found at http://www.xmethods.com
04/10/23 Distributed Computing, M. L. Liu 29
RPC Profile for Service
R PC Pro f ile fo r S e rv ice " W e a th e r - Te m pe ra tu re "
M e th o d Na m e g e tTe m pEn dpo in t UR L h t tp: //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 rS O A PA ct io nM e th o d Na m e s pa ce UR I u rn :x m e th o ds -Te m pe ra tu reI n pu t Pa ra m e te rs z ip c o d e s t rin g
O u tpu t Pa ra m e te rs r e tu r n f lo a t
See sample: TempClient.java
04/10/23 Distributed Computing, M. L. Liu 30
Client program samples
See samples in client folder:– TempClient.java– StockQuoteClient.java– CurrencyClient.java
04/10/23 Distributed Computing, M. L. Liu 31
SOAP data typesSOAP Data Types,
http://www.sdc.iup.edu/outreach/spring2002/webservices/datatypes.htmlUses XML Schema data typesPrimitive Typesstring, boolean, decimal, float, double, duration, dateTime, time, date, gYearMonth, gYear, gMonthDay, gDay, gMonth, hexBinary, base64Binary, anyURI, QName, NOTATION
04/10/23 Distributed Computing, M. L. Liu 32
SOAP data typesDerived 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}
04/10/23 Distributed Computing, M. L. Liu 33
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>
04/10/23 Distributed Computing, M. L. Liu 34
Creating Web Services (server-side SOAP)
O'Reilly Network: Using SOAP with Tomcat [Feb. 27, 2002] http://www.onjava.com/pub/a/onjava/2002/02/27/tomcat.htmApache 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.
04/10/23 Distributed Computing, M. L. Liu 35
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
04/10/23 Distributed Computing, M. L. Liu 36
Creating a SOAP ServiceO'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)
04/10/23 Distributed Computing, M. L. Liu 37
SOAP Service Parameter TypesAll 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
04/10/23 Distributed Computing, M. L. Liu 38
SOAP Service Parameter Typesjava.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)
04/10/23 Distributed Computing, M. L. Liu 39
Sample SOAP Service Implementations
See sample in SOAP folder:
TempService: A temperature service
Exchange: currency exchange service and client
04/10/23 Distributed Computing, M. L. Liu 40
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; }}
04/10/23 Distributed Computing, M. L. Liu 41
Deployment Descriptor<isd:service xmlns:isd="http://xml.apache.org/xml-
soap/deployment" id="urn:onjavaserver"> <isd:provider type="java" scope="Application" methods="add subtract"> <isd:java class="onjava.CalcService"/> </isd:provider>
<isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:faultListener>
</isd:service>
04/10/23 Distributed Computing, M. L. Liu 42
SummarySOAP 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.