560 likes | 1.29k Views
SOAP Protocol. Service Oriented Architecture Protocol Simple Object Access Protocol. W3C Web Service Definition.
E N D
SOAP Protocol Service Oriented Architecture Protocol Simple Object Access Protocol
W3C Web Service Definition • “A Web service is a software system designed to support interoperable machine-to-machine interaction over a network. It has an interface described in a machine-processable format (specifically WSDL). Other systems interact with the Web service in a manner prescribed by its description using SOAP-messages, typically conveyed using HTTP with an XML serialization in conjunction with other Web-related standards”
SOAP History • Microsoft begins investigating XML-based distributed computing in 1997 • Goal: enable applications to communicate by Remote Procedure Calls (RPCs) • Userland publishes a version of the SOAP specification in 1998 (XML-RPC) • IBM supports SOAP 1.1 in 2000 and releases a Java Soap implementation • SOAP 1.2 was a W3C recommendation in 2003
What is SOAP? • Industry’s best effort to standardize on an infrastructure for cross-platform XML distributed computing • A mechanism for defining the unit of communication • SOAP envelope that encloses everything • A Body for the Message which can contain arbitrary XML information • Headers that encapsulate information outside the body
What is SOAP? • A processing model – a set of rules for dealing with SOAP messages in software • A mechanism for error handling – Using SOAP faults, errors can be detected and diagnostic information can be exchanged between participants • An extensibility model – SOAP headers are used to create extensions on top of SOAP
What is SOAP? • A flexible mechanism for data representation – allows for the exchange of data already serialized in some format as well as a convention for representing programming language datatypes in XML • A convention for RPCs and responses • A protocol binding framework – used to send SOAP messages across HTTP connections
Specification Structure • Find the spec at http://www.w3.org/TR/SOAP • Part 1, The Messaging Protocol – foundation info (processing model, extensibility model, message structure) • Part 2, Adjuncts – extensions for proof-of-concept and to provide a baseline for functional interoperable services
SOAP Messaging Framework • What does a message look like? • This one is XML sent by HTTP POST /axis/InventoryCheck.jws HTTP/1.0 Content-Tye application/soap+xml;charset=utf-8 <?xml version=“1.0”encoding=“UTF-8”?> <soapenv:Envelope xmlns:soapenv=“http://www.w3.org/2003/05/soap-envelope” xmlns:xsd=“http://www.w3.org/2001/XMLSchema” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”> <soapenv:Body> <doCheck soapenv:encodingStyle=“http://www.w3.org/2003/05/soap-encoding:> <arg0 xsi:type=“soapenc:string” xmlns:soapenc=“http//schemas.xmlsoa.org/soap/encoding/”>947-TI</arg0> <arg1 xsi:type=“soapenc:int” xmlns:soapenc=“http//schemas.xmlsoa.org/soap/encoding/”>3</arg0> </doCheck> </soapenv:Body> </soapenv:Envelope>
Here is the Response • Response delivered using HTTP Content-Tye application/soap+xml;charset=utf-8 <?xml version=“1.0”encoding=“UTF-8”?> <soapenv:Envelope xmlns:soapenv=“http://www.w3.org/2003/05/soap-envelope” xmlns:xsd=“http://www.w3.org/2001/XMLSchema” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”> <soapenv:Body> <doCheckResponse soapenv:encodingStyle=“http://www.w3.org/2003/05/soap-encoding”> <rpc:result xmlns:rpc=“http://www.w3.org/2003/05/soap-rpc”>return</rpc:result> <return xsi:type”xsdboolean”>true</return> </doCheckResponse> </soapenv:Body> </soapenv:Envelope>
Vertical Extensibility • Why use SOAP? Why not just use HTTP? • Document can be extended using headers without changing the body • Consider adding notary information to a purchase order <po id=“2352” submitted=“2004-01-05 custID=“73852”> <notary:token xmlns:notary=“http://notaries-r-us.com”> XQ34Z-4G5 </notary:token> <billTo> … </billTo </po>
Repercussions • Document schema would have to be extensible • You and consumers would have to agree on how to process extensible parts of the document • SOAP presents headers as an alternative to this technique
Headers • The notary information is carried in the SOAP header as an extension <soapenv:Envelope xmlns:soapenv=“http://www.w3.org/2003/05/soap-envelope”> <soapenv:Header> <notary:token xmlns:notary=“http://notaries-r-su.com”> XQ34Z-4G5 </notary:token> </soapenv:Header> <soapenv:Body> <po id=“2352” submitted=“2004-01-05 custID=“73852”> … normal purchase order info … </po> </soapenv:Body> </soapenv:Envelope>
Header Uses • Extending messaging infrastructure – headers are usually processed by middleware. Applications may not even see them • Defining orthogonal data – A way to send information to the application without having to change the document schema
mustUnderstand Flag • Some headers carry useful but not critical information about the message • Some headers must be processed in order for the body message to make sense <soapenv:Header> <notary:token xmlns:notary=“http://notaries-r-su.com” soapenv:mustUnderstand=“true”> XQ34Z-4G5 </notary:token> </soapenv:Header>
mustUnderstand Flag • If “true” an application must be able to process the header in order to correctly process the message • If “false” or missing, the application can safely process the message without processing the header • The flag allows you to build extensions that fundamentally change the way a document is processed and in a way that is interoperable • Applications can gracefully fail using the flag
SOAP Modules • If you are adding headers you probably want other parties to use your extension • Usually a specification is written that covers the details of the constraints, rules, preconditions, and data formats of the extension • These specifications are called “SOAP modules” • Modules are named with URIs
SOAP Intermediaries • Vertical extensibility is about adding new information within a SOAP message • Horizontal extensibility is about targeting different parts of the same SOAP message to different recipients • Horizontal extensibility is provided by SOAP intermediaries
Why Intermediaries? • Intermediaries are applications that can process parts of a SOAP message as it travels from origin to destination • The route taken by the message is called the SOAP message path Requester Provider Intermediary Intermediary
Why Intermediaries? • Intermediaries can accept and forward SOAP messages • Intermediaries can process messages • Three use cases: • Crossing trust domains • Ensuring scalability • Providing value-added services
Crossing Trust Domains • Employees and customers are probably kept in different trust domains. Internet requests can be processed by an intermediary before crossing into a trusted domain to be processed
Scalability • Highly scalable systems may require buffering of messages and routing of messages based on parameters contained in headers • Users are unaware of the extra processing by intermediaries
Some Value-added Services • Securing message exchanges through untrustworth domains – An intermediary encrypts a message and signs it before sending the message. Another intermediary receives the message, checks the digital signature, and decrypts the message • Notarization/nonrepudiation – A third party records an interaction • Providing message tracing facilities – Discover the path a message took along with timings
Transparent and Explicit Intermediaries • A transparent intermediary is one the client knows nothing about. The client thinks the message is going straight to the service endpoint • An explicit intermediary is one in which the client knows that the message will travel through an intermediary
SOAP Intermediaries • SOAP was designed with intermediaries in mind • Three aspects of intermediary-enabled architecture • How do you pass information to intermediaries? • How do you identify who should process what? • What happens to information that is processed by intermediaries
Identification of Intermediaries • All headers can optionally have a soapenv:role attribute • The value of the attribute is a URI that identifies the intermediary • The URI might mean a particular node (John’s machine) or it might mean a class of nodes (any cache manager along the path) • A given node can play multiple roles (John’s machine might be a cache manager)
Node Processing Steps • Each node must collect all headers targeted at the node • Each node looks at the headers marked “mustUnderstand” and verifies it can process the header in accordance with the rules associated with that header • If if finds a mustUnderstand header it doesn’t recognize, it must immediately stop processing
Special Values of Attribute “role” • http://www.w3.org/2003/05/soap-envelope/role/next – Indicates the header entry’s recipient is the next SOAP node that processes the message – good for hop-by-hop message processing • http://www.w3.org/2003/05/soap-envelope/role/ultimateReceiver – Refers to the final recipient of the message. Omitting this implies that the final recipient should process the header. The final recipient also processes the body
Special Values of Attribute “role” • http://www.w3.org/2003/05/soap-envelope/role/none – Indicates that no SOAP node should process this header. The node still might read information in the node
Types of Intermediaries • Forwarding Intermediary – these intermediaries process only certain headers and forward the message to the next node in the path • Active Intermediary – Process and perhaps modify a message in ways not defined by the message contents. For example adding a digital signature to every outbound message
Intermediary Rules and Headers • All headers targeted at a particular intermediary are removed from the message when it’s forwarded to the next node • The contract implied by a given header is between the sender of that header and the first node satisfying the role to which it’s targeted • Headers that aren’t targeted at a particular intermediary should be forwarded through untouched • Either type of intermediary may do work on the message
Intermediary Rules and Headers • Headers are removed by a target even if they aren’t understood • Two exceptions: • The specification for a given extension indicates that a copy of the header should be placed in the outgoing message (reinserted) • When you want to indicate to an intermediary that extensions targeted at them but not understood should be passed through. Soap 1.2 has a “relay” attribute for this purpose
The SOAP Body • The SOAP Body element surrounds the information that is core to the SOAP message • All immediate children of the Body element are body entries (“bodies”) • Bodies contain arbitrary XML. • Based on the intent of the SOAP message, certain conventions govern the format of the SOAP body (for example, RPCs) • When a node identifies itself as the ultimate recipient, it’s required to process the contents of the body which carries the core of the SOAP message
The SOAP Processing Model Steps a processor must perform when a SOAP message is received: • Determine the set of roles in which the node is to act. The contents of the envelope, including any headers and the body may be inspected in making this determination • Identify all header blocks targeted at the node that are mandatory
The SOAP Processing Model Steps a processor must perform when a SOAP message is received: • If one or more header blocks aren’t understood by the node, generate a single SOAP fault with the value of “Code” set to env:mustUnderstand. No further processing is done. Faults related to the body must not be generated in this step • Process all mandatory headers targeted at the node, and in the case of ultimate receiver, the body. Non-mandatory headers directed at the node can also be processed
The SOAP Processing Model Steps a processor must perform when a SOAP message is received: 5. In the case of an intermediary where the message exchange pattern and processing require the message to be relayed, do so.
Versioning in SOAP • The SOAP envelope does not expose any explicit version information (like HTTP or XML) • Instead, SOAP uses namespaces to define a protocol version using a URI • Web service engines have a choice of how to treat SOAP messages that have a version other than the one the engine is best suited to process
Versioning in SOAP Suppose and engine reads a message: • If the message version is the same as any version the engine knows, it can process the message • If the message version is older than any version the engine knows, it should generate a VersionMismatch fault and attempt to negotiate the protocol version with the client by sending info about the versions it can accept • If the message version is newer than any version the engine knows, it must generate VersionMismatch fault
Processing Headers and Bodies • The SOAP definition of “process” is to fulfill the contract indicated by a particular piece of a SOAP message (header or body) • An intermediary might encrypt the body of a message as it passes through, but this is not “processing” in the SOAP sense. The intermediary isn’t doing something the body requested • A header added to supply data (instead of changing the body and schema) might add “none” to the role to make sure no one tries to process it
Faults: Error Handling in SOAP • A SOAP fault message is a normal SOAP message with a well-known element: soapenv:Fault • The presence of soapenv:Fault signals processors that something has gone wrong • The fault code can signal exactly what is wrong
Faults: Error Handling in SOAP <env:Header> <st:PSAnnounce>Services unavailable after 5PM</st:PSAnnounce> </env:Header> <env:Body> <env:Fault> <env:Code> <env:Value>env:Sender</env:Value> <env:Subcode> <env:Value>st:Invalid PO</env:Value> </env:Subcode> </env:Code> <env:Reason> <env:Text xml:lang=“en-US”>PO didn’t validate</env:Text> </env:Reason> <env:Detail> …</env:Detail> </env:Fault> </env:Body> </env:Envelope
Fault Code • Sender – the problem is missing or incorrect data from the sender • Receiver – Something went wrong with the receiver while processing the message. Not directly attributable to the sender • mustUnderstand – a header was received that was targeted to the receiving node marked mustUnderstand=“true”, and was not understood • VersionMismatch – the namespace on the SOAP envelope isn’t compatible with the version on the receiver
Subcodes • You can specify an arbitrary hierarchy of subcodes <env:Code> <env:Value>env:Sender</env:Value> <env:Subcode> <env:Value>st:Invalid PO</env:Value> </env:Subcode> </env:Code> • Each subcode can contain another subcode
Reason • The Reason element contains human readable descriptions of the fault • The Text element contains the text • Multiple Text elements can be coded but each one should have a different language <env:Reason> <env:Text xml:lang=“en-US”>PO didn’t validate</env:Text> </env:Reason>
Node and Role • An optional Node element can indicate which node (sender, intermediary, ultimate destination) was processing the message when the fault occurred. It contains a URI • The Role element indicates which role the faulting node was playing when the fault occurred.
Fault Details • We may want to pass back complex machine-readable data (stack trace) • You can place anything inside the Detail element
Using Headers in Faults • Since Faults are messages, they can contain headers • Some headers are specifically for faults • NotUnderstood header– used to indicate which header was not understood. Multiple headers of this type can be coded • Upgrade header – used to indicate a versioning problem
Objects in XML: SOAP Data Model • In order for programmers to send Java/C++/VB objects in SOAP envelopes, two concepts were introduced: • SOAP Data model • SOAP encoding
Objects in XML • The SOAP data model is an abstract representation of data structure in Java… • The encoding is a set of rules that map the data model into XML
Java Data Model 129 Class Product { String description; String sku; double unitPrice; } unitPrice Product description sku skateboard 947-x
Object Graphs • Nodes can have outgoing edges (compound values) • Nodes can have only incoming edges (simple values) • Edges coming out of a compound value have names and the node represents a structure • The edge names (accessors) are equivalent to field names in Java • A node with outgoing edges that are only distiquished by position represents an array