Presentation is loading. Please wait.

Presentation is loading. Please wait.

1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic.

Similar presentations


Presentation on theme: "1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic."— Presentation transcript:

1 1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic

2 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

3 3 Web Service Stack Discovery UDDI Transport HTTP, SMTP, FTP, BEEP Description WSDL XML messaging XML-RPC, SOAP, XML Process BPEL4WS, WSCI, WS-CDL

4 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.

5 5 Look into a SOAP message XXX

6 6 Response SOAP message 55.25

7 7 Inside SOAP P53, figure 3-2 Envelope (required) SOAP message Header (optional) Body (required) Fault (optional)

8 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.

9 9 Apache SOAP architecture p69,. Fig 4-3 Service: HelloService.java AXIS SOAP engine rpcrouter servlet SOAP client: HelloClient.java Jakarta Tomcat server SOAP request: Service name: urn:HelloWorld Method name: sayHello Parameter: firstName=“Yuhong” lastName=“Yan” SOAP response: Return value: “Yuhong Yan, welcome to SOAP” “Yuhong Yan, Welcome to SOAP…”sayHello(“Yuhong”, “Yan”) 1 2 3 4 5 Http POST Http GET

10 10 Anatomy of HelloWorld Server side code Client side code SOAP request SOAP response

11 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; }

12 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.

13 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 services Call 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 NameService Method

14 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 message XML data type for the para IN/OUT/INOUT Security options Define the return value

15 15 Request SOAP message Yuhong Yan Remote method name Name of the web service Parameter name. Parameter type. need to match WSDL. Value of the parameter

16 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

17 17 Response SOAP message Yu hong,Yan, Welcome to SOAP Web Service World!

18 18 Inside SOAP P53, figure 3-2 Envelope (required) SOAP message Header (optional) Body (required) Fault (optional)

19 19 Envelope The root element of SOAP message Uses XML namespaces to differentiate versions Two versions 1.1, 1.2 No third string { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/3415167/12/slides/slide_18.jpg", "name": "19 Envelope The root element of SOAP message Uses XML namespaces to differentiate versions Two versions 1.1, 1.2 No third string

20 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

21 21 Header (optional) (2) orsenigo473 P54. the soapheader

22 22 Body Where the transferred data is Data encoding via XML Schemas Yuhong Yan

23 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

24 24 Fault (optional)-2 http://www.s3.org/1999/XMLSchema SOAP-ENV:Client 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. P55. xml part (for faults)

25 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)

26 26 SOAP request message is within HTTP POST POST /axis/services/urn:HelloWorld HTTP/1.0 Content-Type: text/xml; charset=utf-8 Accept: application/soap+xml, application/dime, multipart/related, text/* User-Agent: Axis/1.2alpha Host: localhost:8080 Cache-Control: no-cache Pragma: no-cache SOAPAction: "" Content-Length: 474 Authorization: Basic dXNlcjE6cGFzczE= Here is the HTTP header you see from the log

27 27 SOAP request message is within HTTP POST Yuhong Yan Here is the HTTP body – That is the SOAP message

28 28 SOAP response message is within HTTP GET This should be in HTTP header GET /axis/services/urn:HelloWorld HTTP/1.0 Content-Type: text/xml; charset=utf-8 Accept: application/soap+xml, application/dime, multipart/related, text/* User-Agent: Axis/1.2alpha Host: localhost:8080 ……

29 29 SOAP response message is within HTTP GET Yu hong,Yan, Welcome to SOAP Web Service World!

30 30 Axis Client XML Schema XML data types SOAPServer Java Objects and data types Client follows

31 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

32 32 XML Java Data Mapping in Axis Primitives Beans User Defined Types (classes) Code Demo References: AXIS User Guide AXIS sample code

33 33 Primitives: the mapping table xsd:base64Binary byte[] xsd:boolean boolean xsd:byte byte xsd:dateTime java.util.Calendar xsd:decimal java.math.BigDecimal xsd:double double xsd:floatfloat xsd:hexBinarybyte[] xsd:int int xsd:integer java.math.BigInteger xsd:long long xsd:QName javax.xml.namespace.QName xsd:short short xsd:stringjava.lang.String


Download ppt "1 SOAP : Simple Object Access Protocol Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic."

Similar presentations


Ads by Google