1 soap : simple object access protocol dr. yuhong yan nrc-iit-fredericton internet logic
TRANSCRIPT
![Page 1: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/1.jpg)
1
SOAP : Simple Object Access Protocol
Dr. Yuhong YanNRC-IIT-Fredericton
Internet logic
![Page 2: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/2.jpg)
2
Service Oriented Architecture (SOA)/Web Service triangle
From “Web Services Architecture W3C Working Draft”http://www.w3.org/TR/2002/WD-ws-arch-20021114/
WSDL
UDDI
SOAP
![Page 3: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/3.jpg)
3
Web Service Stack
Discovery UDDI
Transport HTTP, SMTP, FTP, BEEP
Description WSDL
XML messaging XML-RPC, SOAP, XML
Process BPEL4WS, WSCI, WS-CDL
![Page 4: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/4.jpg)
4
SOAP (Simple Object Access Protocol)
SOAP is a lightweight protocol for exchange of information in a decentralized, distributed environment. It is an XML based protocol that consists of three parts: an envelope that defines a framework for describing what is in a message and how to process it, a set of encoding rules for expressing instances of application-defined data types, and a convention for representing remote procedure calls and responses.
![Page 5: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/5.jpg)
5
Look into a SOAP message
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body> <ns1:getQuote
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:xmltoday-delayed-quotes">
<symbol xsi:type="xsd:string">XXX</symbol> </ns1:getQuote> </soapenv:Body></soapenv:Envelope>
![Page 6: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/6.jpg)
6
Response SOAP message
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body> <ns1:getQuoteResponse
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:xmltoday-delayed-quotes">
<ns1:getQuoteReturn href="#id0"/> </ns1:getQuoteResponse> <multiRef id="id0" soapenc:root="0"
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:float" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">55.25</multiRef>
</soapenv:Body></soapenv:Envelope>
![Page 7: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/7.jpg)
7
Inside SOAP
P53, figure 3-2
Envelope (required)
SOAP message
Header (optional)
Body (required)
Fault (optional)
![Page 8: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/8.jpg)
8
Why SOAP
• Inter-application communication between systems written in arbitrary languages, across the Internet.
• An XML-based protocol for exchanging messages over Internet transport protocols, like HTTP, SMTP, FTP, etc.
• SOAP is platform-independent.
![Page 9: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/9.jpg)
9
Apache SOAP architecture
p69,. Fig 4-3
Service:HelloService.java
AXIS SOAP enginerpcrouter servlet
SOAP client: HelloClient.java
Jakarta Tomcat server
SOAP request:Service name: urn:HelloWorldMethod name: sayHelloParameter: firstName=“Yuhong”
lastName=“Yan”SOAP response:
Return value: “Yuhong Yan, welcome to SOAP”
“Yuhong Yan, Welcome to SOAP…”sayHello(“Yuhong”, “Yan”)
12
3
4
5Http POST
Http GET
![Page 10: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/10.jpg)
10
Anatomy of HelloWorld
• Server side code• Client side code• SOAP request• SOAP response
![Page 11: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/11.jpg)
11
HelloWorldService.java
package samples.HelloWorld;
public class HelloWorldService{ public String sayHello(String firstName, String lastName) throws Exception { String aString = firstName + “ " + lastName + ", welcome to SOAP Web Service
World!"; return aString; } public String addString(String symbol, String dataType) throws Exception { String aString = symbol + dataType; return aString; }}
![Page 12: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/12.jpg)
12
TestClient
public class TestClient{ public static void main(String args[]) { try { Options opts = new Options( args ); args = opts.getRemainingArgs();
Parse the arg[ ] into options (user,url,etc) and non-options
args.
get non-options args.
![Page 13: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/13.jpg)
13
TestClient.java (2)
Service service = new Service();Call call = (Call) service.createCall();call.setTargetEndpointAddress( new
java.net.URL(opts.getURL()) );if( args[0].equals("1") ) call.setOperationName( new
QName("urn:HelloWorld", "sayHello") );else call.setOperationName( new
QName("urn:HelloWorld", "addString") );
The start point of access SOAP web servicesCall invokes SOAP web services
Default URL "http://localhost:8080/axis/servlet/AxisServlet
Or You can use the SOAP endpoint as in WSDL"http://localhost:8080/axis/services/urn:HelloWorld"
Service Name Service Method
![Page 14: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/14.jpg)
14
TestClient.java
call.addParameter( “p1", XMLType.XSD_STRING, ParameterMode.IN );
call.addParameter( “p2", XMLType.XSD_STRING, ParameterMode.IN );
call.setReturnType( XMLType.XSD_STRING );
call.setUsername( opts.getUser() );call.setPassword( opts.getPassword() );
Add the parameters for the remote method
Parameter name. Arbitrary. Appear in request SOAP messageXML data type for the para
IN/OUT/INOUT
Security options
Define the return value
![Page 15: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/15.jpg)
15
Request SOAP message
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body> <ns1:sayHello
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:HelloWorld">
<p1 xsi:type="xsd:string">Yuhong</p1> <p2 xsi:type="xsd:string">Yan</p2> </ns1:sayHello> </soapenv:Body></soapenv:Envelope>
Remote method name
Name of the web serviceParameter name.
Parameter type. need to match WSDL. Value of the parameter
![Page 16: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/16.jpg)
16
TestClient.java
String res = (String) call.invoke( new Object[] { args[1], args[2] } );
System.out.println( "Return is: " + res ); } catch( Exception e ) { e.printStackTrace(); } } }//end of class
Return value
Invoke the web service
Passing parameters
![Page 17: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/17.jpg)
17
Response SOAP message
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body> <ns1:sayHelloResponse
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:HelloWorld">
<ns1:sayHelloReturn xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">Yuhong,Yan, Welcome to SOAP Web Service World!</ns1:sayHelloReturn>
</ns1:sayHelloResponse> </soapenv:Body></soapenv:Envelope>
![Page 18: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/18.jpg)
18
Inside SOAP
P53, figure 3-2
Envelope (required)
SOAP message
Header (optional)
Body (required)
Fault (optional)
![Page 19: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/19.jpg)
19
Envelope
• The root element of SOAP message• Uses XML namespaces to differentiate versions• Two versions 1.1, 1.2• No third string
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
![Page 20: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/20.jpg)
20
Header (optional)
• For authentication, transaction management, and payment authorization
• Two defined attributes– Actor attribute: the chained node– MustUnderstand attribute: force the recipient
to process the element, if not understandable, return a fault
![Page 21: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/21.jpg)
21
Header (optional) (2)
<SOAP-ENV:Header><ns1:PaymentAccount xmlns:ns1=“urn:ecerami”
SOAP-ENV:mustUnderstand=“true”>orsenigo473
</ns1:PaymentAccount></SOAP-ENV:Header>
P54. the soapheader
![Page 22: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/22.jpg)
22
Body
• Where the transferred data is• Data encoding via XML Schemas
<soapenv:Body> <ns1:sayHello soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:HelloWorld"> <p1 xsi:type="xsd:string">Yuhong</p1> <p2 xsi:type="xsd:string">Yan</p2> </ns1:sayHello> </soapenv:Body>
![Page 23: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/23.jpg)
23
Fault (optional)
• faultCode– SOAP-ENV:VersionMismatch– SOAP-ENV:MustUnderstand– SOAP-ENV:Client (non existing methods)– SOAP-ENV:Server (not able to access DB)
• faultString• faultActor• detail
![Page 24: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/24.jpg)
24
Fault (optional)-2
<?xml version=‘1.0’ encoding=‘UTF-8’?><SOAP-ENV:Envelope
xmlns:SOAP-ENV=“http://schemas.xmlsoap.org/soap/envelope/”xmlns:xsi=“http://www.w3.org/1999/XMLSchema-instance”xmlns:xsd=“http://www.s3.org/1999/XMLSchema”><SOAP-ENV:Body>
<SOAP-ENV:Fault><faultcode xsi:type=“xsd:string”>SOAP-ENV:Client</faultcode><faultstring xsi:type=“xsd:string”>
Failed to locate method (ValidateCreditCard) in class(examplesCreditCard) at /usr/local/ActivePerl-5.6/lib/site_perl/5.6.0/SOAP/Lite.pm line 1555.
</faultstring></SOAP-ENV:Fault>
</SOAP-ENV:Body></SOAP-ENV:Envelope>
P55. xml part (for faults)
![Page 25: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/25.jpg)
25
SOAP message inside HTTP message
• SOAP is inside a HTTP message• How client-server talks in HTTP
– The client identifies the server via a URI– connects to it using the underlying TCP/IP
network– issues a HTTP request message (POST)– receives a HTTP response message (GET)
![Page 26: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/26.jpg)
26
SOAP request message is within HTTP POST
POST /axis/services/urn:HelloWorld HTTP/1.0Content-Type: text/xml; charset=utf-8Accept: application/soap+xml, application/dime,
multipart/related, text/*User-Agent: Axis/1.2alphaHost: localhost:8080Cache-Control: no-cachePragma: no-cacheSOAPAction: ""Content-Length: 474Authorization: Basic dXNlcjE6cGFzczE=
Here is the HTTP header you see from the log
![Page 27: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/27.jpg)
27
SOAP request message is within HTTP POST
<?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body> <ns1:sayHello
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:HelloWorld">
<p1 xsi:type="xsd:string">Yuhong</p1> <p2 xsi:type="xsd:string">Yan</p2> </ns1:sayHello> </soapenv:Body></soapenv:Envelope>
Here is the HTTP body – That is the SOAP message
![Page 28: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/28.jpg)
28
SOAP response message is within HTTP GET
This should be in HTTP header
GET /axis/services/urn:HelloWorld HTTP/1.0Content-Type: text/xml; charset=utf-8Accept: application/soap+xml, application/dime,
multipart/related, text/*User-Agent: Axis/1.2alphaHost: localhost:8080……
![Page 29: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/29.jpg)
29
SOAP response message is within HTTP GET
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body> <ns1:sayHelloResponse
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="urn:HelloWorld">
<ns1:sayHelloReturn xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">Yuhong,Yan, Welcome to SOAP Web Service World!</ns1:sayHelloReturn>
</ns1:sayHelloResponse> </soapenv:Body></soapenv:Envelope>
![Page 30: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/30.jpg)
30
Axis Client
XMLSchema
XMLdata types
SOAP ServerJava Objects
and data types
Client
follows
![Page 31: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/31.jpg)
31
Axis client
• Map java data types to XSD data type• Serialize java objects into XML• Send SOAP request to server (not necessarily
Axis server)• Interpret SOAP response
![Page 32: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/32.jpg)
32
XML <-> Java Data Mapping in Axis
• Primitives• Beans• User Defined Types (classes)• Code Demo
References:
AXIS User Guide
AXIS sample code
![Page 33: 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic](https://reader035.vdocument.in/reader035/viewer/2022062515/56649c7d5503460f949327f3/html5/thumbnails/33.jpg)
33
Primitives: the mapping tablexsd:base64Binary byte[]xsd:boolean booleanxsd:byte bytexsd:dateTime java.util.Calendarxsd:decimal java.math.BigDecimalxsd:double doublexsd:float floatxsd:hexBinary byte[]xsd:int intxsd:integer java.math.BigIntegerxsd:long longxsd:QName javax.xml.namespace.QNamexsd:short shortxsd:string java.lang.String