1 / 33

SOAP : Simple Object Access Protocol

SOAP : Simple Object Access Protocol. Dr. Yuhong Yan NRC-IIT-Fredericton Internet logic. Service Oriented Architecture (SOA)/Web Service triangle. UDDI. Services. WSDL. SOAP. From “Web Services Architecture W3C Working Draft” http://www.w3.org/TR/2002/WD-ws-arch-20021114/.

tiva
Télécharger la présentation

SOAP : Simple Object Access Protocol

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. Service Oriented Architecture (SOA)/Web Service triangle UDDI Services WSDL SOAP From “Web Services Architecture W3C Working Draft”http://www.w3.org/TR/2002/WD-ws-arch-20021114/

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

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

  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>

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

  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. Apache SOAP architecture 4 Service:HelloService.java sayHello(“Yuhong”, “Yan”) “Yuhong Yan, Welcome to SOAP…” 3 SOAP client: HelloClient.java AXIS SOAP engine rpcrouter servlet 1 SOAP request:Service name: urn:HelloWorldMethod name: sayHelloParameter: firstName=“Yuhong” lastName=“Yan” 2 Jakarta Tomcat server 5 SOAP response: Return value: “Yuhong Yan, welcome to SOAP” Http POST Http GET p69,. Fig 4-3

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

  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. 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. TestClient.java (2) The start point of access 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" Call invokes SOAP web services 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") ); Service Name Service Method

  14. TestClient.java Add the parameters for the remote method Parameter name. Arbitrary. Appear in request SOAP message XML data type for the para 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() ); IN/OUT/INOUT Define the return value Security options

  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"> <p1xsi:type="xsd:string">Yuhong</p1> <p2xsi:type="xsd:string">Yan</p2> </ns1:sayHello> </soapenv:Body> </soapenv:Envelope> Remote method name Name of the web service Parameter name. Parameter type. need to match WSDL. Value of the parameter

  16. TestClient.java Invoke the web service Return value Passing parameters 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

  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 ServiceWorld!</ns1:sayHelloReturn> </ns1:sayHelloResponse> </soapenv:Body> </soapenv:Envelope>

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

  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/"

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

  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"> <p1xsi:type="xsd:string">Yuhong</p1> <p2xsi:type="xsd:string">Yan</p2> </ns1:sayHello> </soapenv:Body>

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

  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. SOAP request message is within HTTP POST Here is the HTTP header you see from the log 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=

  27. SOAP request message is within HTTP POST Here is the HTTP body – That is the 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"> <p1xsi:type="xsd:string">Yuhong</p1> <p2xsi:type="xsd:string">Yan</p2> </ns1:sayHello> </soapenv:Body> </soapenv:Envelope>

  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. 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 ServiceWorld!</ns1:sayHelloReturn> </ns1:sayHelloResponse> </soapenv:Body> </soapenv:Envelope>

  30. Axis Client Client XML Schema follows Java Objects and data types XML data types SOAP Server

  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. XML <-> Java Data Mapping in Axis • Primitives • Beans • User Defined Types (classes) • Code Demo References: AXIS User Guide AXIS sample code

  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:float float xsd:hexBinary byte[] xsd:int int xsd:integer java.math.BigInteger xsd:long long xsd:QName javax.xml.namespace.QName xsd:short short xsd:string java.lang.String

More Related