420 likes | 435 Views
Learn about the Simple Object Access Protocol (SOAP) - standards, anatomy of messages, encoding, communication model, bindings, and limitations. Dive deep into SOAP version 1.2 specifications and examples.
E N D
G52IWS: Simple Object Access Protocol (SOAP) Chris Greenhalgh 2007-10-23
Contents • Standards • Anatomy of a SOAP message • SOAP encoding • SOAP message exchange model • SOAP communication • SOAP bindings for transport protocols • Limitations of SOAP See “Developing Java Web Services”, chapter 4 pp 103-139 & 199
Standards • SOAP 1.0 • XML-based RPC published in 1999 • SOAP 1.1 • W3C “Note” - May 2000 • Submitted by DevelopMentor, IBM, Lotus, Microsoft, UserLand Software • Currently SOAP version 1.2 • W3C Recommendation (standard), April 2007 • From XML Protocol Working Group • http://www.w3.org/TR/soap/
SOAP version 1.2 specification parts • SOAP Version 1.2 Part0: Primer • http://www.w3.org/TR/2007/REC-soap12-part0-20070427/ (errata) • SOAP Version 1.2 Part1: Messaging Framework • http://www.w3.org/TR/2007/REC-soap12-part1-20070427/ (errata) • SOAP Version 1.2 Part2: Adjuncts • http://www.w3.org/TR/2007/REC-soap12-part2-20070427/ (errata) • Including data model, encoding, rpc representation, http binding • SOAP Version 1.2 Specification Assertions and Test Collection • http://www.w3.org/TR/2007/REC-soap12-testcollection-20070427/ (errata)
SOAP scope • Syntax & semantics for representing XML documents as structured SOAP messages • Encoding standards for representing data in SOAP messages • Communication model for exchanging SOAP messages • Bindings for transport protocols • Conventions for RPC and messaging
SOAP not-scope • Garbage collection • Object by reference • Object activation • Message batching
Anatomy of a SOAP message • Example… • Document encoded • HTTP binding
Example Request POST /BookPrice HTTP/1.1 Host: catalog.acmeco.com Content-Type: text/xml; charset="utf-8" Content-Length: 640 SOAPAction: "GetBookPrice" <SOAP-ENV:Envelope xmlns:SOAP ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3c.org/2001/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Header> <person:mail xmlns:person="http://acmeco.com/Header/"> xyz@acmeco.com </person:mail> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:GetBookPrice xmlns:m="http://www.wiley.com/jws.book.priceList"> <bookname xsi:type='xsd:string'> Developing Java Web Services </bookname> </m:GetBookPrice> </SOAP-ENV:Body> </SOAP-ENV: Envelope> “Developing Java Web Services”, listing 4.1
Example Response HTTP/1.1 200 OK Content-Type: text/xml; charset="utf-8" Content-Length: 640 <SOAP-ENV:Envelope xmlns:SOAP-ENV=http://schemas.xmlsoap.org/soap/envelope/ xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance“ xmlns:xsd=http://www.w3c.org/2001/XMLSchema SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/> <SOAP-ENV:Header> <wiley:Transaction xmlns:wiley="http://jws.wiley.com/2002/booktx" SOAP-ENV:mustUnderstand="1"> 5 </wiley:Transaction> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:GetBookPriceResponse xmlns:m=" http://www.wiley.com/jws.book.priceList"> <Price>50.00</Price> </m:GetBookPriceResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope> “Developing Java Web Services”, listing 4.2
Important namespaces • SOAP Envelope • http://schemas.xmlsoap.org/soap/envelope/ (SOAP 1.1) • http://www.w3.org/2001/06/soap-envelope (SOAP 1.2) • SOAP Encoding • http://schemas.xmlsoap.org/soap/encoding/ (SOAP 1.1) • http://www.w3.org/2001/06/soap-encoding (SOAP 1.2) • XML Schema • http://www.w3c.org/2001/XMLSchema-instance • http://www.w3c.org/2001/XMLSchema • Application-specific • E.g. http://jws.wiley.com/2002/booktx
SOAP message structure • Envelope • single XML root element • Must be in appropriate namespace (for SOAP version), or will be ignored! • Header • optional • Body • Attachments • Optional • Typically carried outside envelope (see e.g. HTTP binding)
SOAP Message structure “Developing Java Web Services”, figure 4.1
SOAP Header • First child of SOAP Envelope • Optional • Contains zero or more “Header entries” • XML elements • May be qualified by attributes: • SOAP-ENV:actor (SOAP 1.1) or role (SOAP 1.2) • Identifies target SOAP application (see later) • SOAP-ENV:mustUnderstand • Specifies whether the header entry can be ignored if it is not understood
Example Request: SOAP Header POST /BookPrice HTTP/1.1 Host: catalog.acmeco.com Content-Type: text/xml; charset="utf-8" Content-Length: 640 SOAPAction: "GetBookPrice" <SOAP-ENV:Envelope xmlns:SOAP ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3c.org/2001/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Header> <person:mail xmlns:person="http://acmeco.com/Header/"> xyz@acmeco.com </person:mail> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:GetBookPrice xmlns:m="http://www.wiley.com/jws.book.priceList"> <bookname xsi:type='xsd:string'> Developing Java Web Services </bookname> </m:GetBookPrice> </SOAP-ENV:Body> </SOAP-ENV: Envelope> “Developing Java Web Services”, listing 4.1
SOAP Body • Exactly one, child of SOAP Envelope • Contains one or more body block entries • E.g. • RPC method and its parameters • Target application (receiver) specific data • SOAP fault for reporting errors/status • Encoding of data indicated by encodingStyle attribute
Example Request: SOAP Body (RPC) POST /BookPrice HTTP/1.1 Host: catalog.acmeco.com Content-Type: text/xml; charset="utf-8" Content-Length: 640 SOAPAction: "GetBookPrice" <SOAP-ENV:Envelope xmlns:SOAP ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3c.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3c.org/2001/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Header> <person:mail xmlns:person="http://acmeco.com/Header/"> xyz@acmeco.com </person:mail> </SOAP-ENV:Header> <SOAP-ENV:Body> <m:GetBookPrice xmlns:m="http://www.wiley.com/jws.book.priceList"> <bookname xsi:type='xsd:string'> Developing Java Web Services </bookname> </m:GetBookPrice> </SOAP-ENV:Body> </SOAP-ENV: Envelope> “Developing Java Web Services”, listing 4.1
SOAP Fault • Communicates error/status information • May be used as a body entry or within a Body element • Has: • Faultcode,e.g. • VersionMismatch – e.g. invalid SOAP namespace • MustUnderstand – failed to understand (!) • Client – originates from client • Server – error from server processing • Faultstring – textual • Faultactor – responsible for the SOAP fault • Detail – application-specific error/status information
SOAP Fault Example: MustUnderstand <SOAP-ENV:Envelope xmlns:SOAP-ENV ="http://www.w3.org/2001/06/soap-envelope/“ SOAP-ENV:encodingStyle= "http://www.w3.org/2001/06/soap-encoding/” xmlns:fx="http://www.w3.org/2001/06/soap-faults/"> <SOAP-ENV:Header> <fx:misUnderstood qname="wiley:Catalog“ xmlns:wiley="http://jws.wiley.com/2002/bookList/" /> </SOAP-ENV:Header> <SOAP-ENV:Body> <SOAP-ENV:Fault> <faultcode>SOAP-ENV:mustUnderstand</faultcode> <faultstring>Could not understand Header element</faultstring> </SOAP-ENV:Fault> </SOAP_ENV:Body> </SOAP-ENV:Envelope> “Developing Java Web Services”, listing 4.10
SOAP Fault examples: server, client <SOAP-ENV:Fault> <faultcode>SOAP-ENV:Server</faultcode> <faultstring> Server OS Internal failure - Reboot server</faultstring> <faultactor>http://abzdnet.net/net/keysoap.asp</faultactor> </SOAP-ENV:Fault> <SOAP-ENV:Fault> <faultcode>Client</faultcode> <faultstring>Invalid Request</faultstring> <faultactor>http://jws.wiley.com/GetCatalog</faultactor> </SOAP-ENV:Fault> “Developing Java Web Services”, listings 4.7 & 4.8
SOAP Attachments • May be in any data format • Envelope is always XML • E.g. in MIME multipart/related SOAP message • SOAP envelope is in first part • Other parts are attachments • Referred to from envelope using Content-ID or Content-Location • E.g….
MIME-Version: 1.0 Content-Type: Multipart/Related; boundary=MIME_boundary; type=text/xml; start="<http://jws.wiley.com/coverpagedetails.xml>" Content-Description: SOAP message description. --MIME_boundary— Content-Type: text/xml; charset=UTF-8 Content-Transfer-Encoding: 8bit Content-ID: <http://jws.wiley.com/coverpagedetails.xml> Content-Location: http://jws.wiley.com/coverpagedetails.xml <?xml version='1.0' ?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> <SOAP-ENV:Body> <theCoverPage href="http://jws.wiley.com/DevelopingWebServices.gif"/> </SOAP-ENV:Body> </SOAP-ENV:Envelope> --MIME_boundary– Content-Type: image/gif Content-Transfer-Encoding: binary Content-ID: <http://jws.wiley.com/DevelopingWebServices.gif> Content-Location: http://jws.wiley.com/DevelopingWebServices.gif <!--...binary GIF image... - -> --MIME_boundary--
SOAP encoding • Data representation in SOAP as either: • Literals, as defined in XML Schema • Encoded values, as defined in SOAP Encoding • Specified in XML Schema Part 2 • Encoding identified by SOAP-ENV:encodingStyle attribute
SOAP Encoding in SOAP 1.1 • Defines standard XML encoding for commonly observed programming language types • Simple types • Enumerations • Compound types, e.g. structs, objects • Arrays • References
SOAP Encoding in SOAP 1.2 • Defines an abstract SOAP Data Model • A graph of nodes, optionally associated with types, with terminal nodes optionally associated with a literal value • Simple type = terminal node with literal value and optional type • Complex type = non-terminal node, may be • Structure with named outgoing edges • Array with unnamed outgoing edges • Defines a separate standard encoding of this Data Model to/from XML
Programming Language binding • Specifies a mapping between programming language types and SOAP Data Model (SOAP 1.2) or common abstract types (SOAP 1.1) • E.g. Java SOAP 1.2 Data Model • Class instance => node, properties => edges • Array => node, elements => unnamed edges • Primitive value => terminal node, Unicode encoding of value => literal node value
SOAP 1.1 Encoding example: array <?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:handleArray soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://DefaultNamespace"> <sa soapenc:arrayType="xsd:string[3]" xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"> <sa xsi:type="xsd:string">b</sa> <sa xsi:type="xsd:string">a</sa> <sa xsi:type="xsd:string">c</sa> </sa> </ns1:handleArray> </soapenv:Body> </soapenv:Envelope>
SOAP message exchange model • SOAP is • Stateless • One-way • Composable, e.g. WSDL operation types • One-way • Request-response • Solicit-response • Notification • Messaging framework • For transferring XML messages • Between SOAP applications (“Nodes”)
SOAP Node types • SOAP sender • Generates & sends the message • SOAP receiver • Ultimately receives and processes the message • May generate a SOAP response, message or fault as a result • SOAP intermediary • Zero or more • Receives, processes (e.g. routes) and resends the message “Developing Java Web Services”, figure 4.2 *
SOAP intermediary types • Forwarding intermediaries • Uses and updates the SOAP header blocks to pass the message (body unchanged) on to the next node • Active intermediaries • Perform addition (potentially arbitrary) processing on the SOAP message before sending
SOAP Actors (roles in 1.2) • Identifies a particular SOAP node in a SOAP header entry • URI • Or special value:http://schemas.xmlsoap.org/soap/actor/next
Notes • SOAP does not define how messages should be routed • SOAP does allow information for intermediaries and receivers to be encoded in header elements
SOAP communication • Two communication models: • SOAP RPC – remote-procedure call • Synchronous request-response • Request encodes method & arguments • Response encodes result value or fault • SOAP Messaging • Document-driven • Synchronous and/or asynchronous messaging
SOAP RPC • Defined in SOAP Spec. part 2 • Request body is • Element encoding method to invoke • Zero or more child elements, each encoding one argument • May be identified by order and/or by name • Response body is • Element(s) encoding return value(s) or • Element encoding SOAP fault
SOAP Messaging • Each message body is an XML document or literal • Body element type typically identifies the message type • And therefore how/by what it should be handled • There is no distinct encoding step • It is logically XML being sent/received, not programming language values
SOAP bindings for transport protocols • SOAP messages can be sent in many different ways • Over HTTP • Over HTTP/SSL • Over SMTP (email) • Over a messaging provider (i.e. MOM implementation) • SOAP separates the abstract message/communication model from the transport-specific rules for “binding” • Binding also specifies specific value encoding to use
SOAP over HTTP • The commonest (at one time, only) binding is to HTTP • Esp. for SOAP RPC request/response => HTTP request/response
Example SOAP request using HTTP POST /SampleServer2.jws HTTP/1.0 Content-Type: text/xml; charset=utf-8 Accept: application/soap+xml, application/dime, multipart/related, text/* User-Agent: Axis/1.4 Host: localhost:8090 Cache-Control: no-cache Pragma: no-cache SOAPAction: "" Content-Length: 824 <?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:addTwoNumbers soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://DefaultNamespace"> <a href="#id0"/> <b href="#id1"/> </ns1:addTwoNumbers> <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/">1.0</multiRef> <multiRef id="id1" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="xsd:float" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">2.0</multiRef> </soapenv:Body> </soapenv:Envelope
Example SOAP response using HTTP HTTP/1.1 200 OK Content-Type: text/xml; charset=utf-8 Server: Jetty(6.1.5) <?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> <urlSet xmlns="http://www.cs.nott.ac.uk/~cmg/G52IWS/SampleWebServiceTypes"> <url xmlns="">http://www.cs.nott.ac.uk/~cmg/index.html</url> <url xmlns="">http://www.cs.nott.ac.uk/~bnk/index.html</url> <url xmlns="">http://www.mrl.nott.ac.uk/~cmg/index.html</url> </urlSet> </soapenv:Body> </soapenv:Envelope>
Example SOAP request using SMTP To: <webservices@wiley.com> From: <nramesh@post.harvard.edu> Reply-To: <nramesh@post.harvard.edu> Date: Tue, 03 May 2002 02:21:00 -0200 Message-Id: <1E23B5F132D3EF3C44BCB54532167C5@post.harvard.edu> MIME-Version: 1.0 Content-Type: text/xml; charset=utf-8 Content-Transfer-Encoding: QUOTED-PRINTABLE <?xml version="1.0" encoding="UTF-8"?> <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/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <SOAP-ENV:Body> <m:getStatusInfo xmlns:m="http://jws.wiley.com/"> <PurchaseOrderNo>JWS739794-04</PurchaseOrderNo> </m:getStatusInfo> </SOAP-ENV:Body> </SOAP-ENV:Envelope> “Developing Java Web Services”, listing 4.31
Limitations of SOAP • The specification does not address message reliability, secure message delivery, transactional support, and its communication requirements of a SOAP implementation. • The specification does not address message reliability, secure message delivery, transactional support, and its communication requirements of a SOAP implementation. • The specification does not address message reliability, secure message delivery, transactional support, and its communication requirements of a SOAP implementation. • The specification does not address how to handle SOAP messages out of a SOAP implementation.
Relation to Examples • SampleServer2.jws • RPC model • Default HTTP binding • RPC & SOAP 1.1 encoding of data • Follows “natural” mappings of programming language types • SampleWebService.wsdl • Still request-response (RPC-style) synchronous interaction • Document/literal data • Specific mapping to/from programming language (if any) is outside the scope of SOAP/WSDL/etc.
Further resources • Web page includes AXIS tcpmon records of sample web service interactions • http://www.cs.nott.ac.uk/~cmg/G52IWS/sample_soap/index.html