SOAP is an acronym for Simple Object Access Protocol. It is an XML-based messaging protocol for exchanging information among computers.
- Platform- and language-independent.
- communication protocol designed to communicate via Internet to Exchange complete documents or call a remote procedure.
- Extend HTTP for XML messaging.
- Provides data transport for Web services.
- Enables client applications to easily connect to remote services and invoke remote methods.
Similar Other frameworks :CORBA, DCOM, and Java RMI
SOAP message
is an ordinary XML document containing the following elements −
- Envelope − Defines the start and the end of the message. It is a mandatory element
- Header − Contains any optional attributes of the message used in processing the message, either at an intermediary point or at the ultimate end-point. It is an optional element. For example, the It can be used to specify a digital signature for password-protected services.
- Header elements can occur multiple times.
- Headers are intended to add new features and functionality.
- contains header entries defined in a namespace.
- is encoded as the first immediate child element of the SOAP envelope.
Attributes −
Actor attribute
The SOAP protocol defines a message path as a list of SOAP service nodes. Each of these intermediate nodes can perform some processing and then forward the message to the next node in the chain. By setting the Actor attribute, the client can specify the recipient of the SOAP header.
MustUnderstand attribute
It indicates whether a Header element is optional or mandatory. If set to true, the recipient must understand and process the Header attribute according to its defined semantics, or return a fault.
- is encoded as the first immediate child element of the SOAP envelope.
- Body − Contains the XML data comprising the message being sent. It is a mandatory element.
- Fault − An optional Fault element that provides information about errors that occur while processing the message.
- For HTTP binding, a successful response is linked to the 200 to 299 range of status codes.
- SOAP Fault is linked to the 500 to 599 range of status codes.
<?xml version = "1.0"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV = "http://.../2001/12/soap-envelope" SOAP-ENV:encodingStyle = "http://.../2001/12/soap-encoding"> <SOAP-ENV:Header> ... ... </SOAP-ENV:Header> <SOAP-ENV:Body> ... ... <SOAP-ENV:Fault> ... ... </SOAP-ENV:Fault> ... </SOAP-ENV:Body> </SOAP_ENV:Envelope>
SOAP Envelope
It solves the problem of knowing when you are done receiving a message and are ready to process it.- Every SOAP message has a root Envelope element which is a mandatory.
- Every Envelope element must contain exactly one Body element.
- If an Envelope contains a Header element, it must contain no more than one, and it must appear as the first child of the Envelope, before the Body.
- It changes when SOAP versions change.
- Specified using the ENV namespace prefix and the Envelope element.
- SOAP Processor
v1.2-compliant >>generates a VersionMismatch fault if it receives a message that does not include the v1.2 envelope namespace.
Request
<?xml version = "1.0"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV = " http://.../2001/12/soap-envelope" SOAP-ENV:encodingStyle = " http://..../2001/12/soap-encoding"> <SOAP-ENV:Header> <t:Transaction xmlns:t = "http://www.xyz.com/transaction/" SOAP-ENV:mustUnderstand = "true">5 </t:Transaction> </SOAP-ENV:Header>
<SOAP-ENV:Body> <m:GetQuotation xmlns:m = "http://www.tp.com/Quotation"> <m:Item>Computers</m:Item> </m:GetQuotation> </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Response
<?xml version = "1.0"?> <SOAP-ENV:Envelope> ........ <SOAP-ENV:Body> <m:GetQuotationResponse xmlns:m = "http://www.tp.com/Quotation"> <m:Quotation>This is Qutation</m:Quotation> </m:GetQuotationResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>The Quotation service might be implemented using an EJB running in an application server; if so, the SOAP processor would be responsible for mapping the body information as parameters into and out of the EJB implementation of the GetQuotationResponse service.
SOAP - Encoding
It enables the SOAP message to indicate specific data types, such as integers, floats, doubles, or arrays.<?xml version = '1.0' encoding = 'UTF-8'?> <SOAP-ENV:Envelope xmlns:SOAP-ENV = "http://..../2001/12/soap-envelope" xmlns:xsi = "http://..../2001/XMLSchema-instance" xmlns:xsd = "http://...../2001/XMLSchema"> <SOAP-ENV:Body> <ns1:getPriceResponse xmlns:ns1 = "urn:examples:priceservice" SOAP-ENV:encodingStyle = "http://...../2001/12/soap-encoding"> <return xsi:type = "xsd:double">54.99</return> </ns1:getPriceResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
A]Scalar Types
SOAP adopts all the built-in simple types specified by the XML Schema specification. This includes strings, floats, doubles, and integers.Below Example highlighted in green
B] Compound Types
SOAP arrays have a very specific set of rules, which require that you specify both the element type and array size. SOAP also supports multidimensional arrays, but not all SOAP implementations support multidimensional functionality.To create an array, you must specify it as an xsi:type of array.
Below Example highlighted in red.
<?xml version = '1.0' encoding = 'UTF-8'?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV = "http://..../2001/12/soap-envelope"
xmlns:xsi = "http://..../2001/XMLSchema-instance"
xmlns:xsd = "http://..../2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:getPriceResponse
xmlns:ns1 = "urn:examples:priceservice"
SOAP-ENV:encodingStyle = "http://..../2001/12/soap-encoding">
<return xsi:type = "xsd:double">54.99</return>
<return xmlns:ns2 = "http://..../2001/09/soap-encoding"
xsi:type = "ns2:Array" ns2:arrayType = "xsd:double[2]">
<item xsi:type = "xsd:double">54.99</item>
<item xsi:type = "xsd:double">19.99</item>
</return>
</ns1:getPriceResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Structs contain multiple values, but each element is specified with a unique accessor element. For example, consider an item within a product catalog. In this case, the struct might contain a product SKU, product name, description, and price.
<?xml version = '1.0' encoding = 'UTF-8'?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV = "http://..../2001/12/soap-envelope"
xmlns:xsi = "http://..../2001/XMLSchema-instance"
xmlns:xsd = "http://..../2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:getProductResponse
xmlns:ns1 = "urn:examples:productservice"
SOAP-ENV:encodingStyle = "http://..../2001/12/soap-encoding">
<return xmlns:ns2 = "urn:examples" xsi:type = "ns2:product">
<name xsi:type = "xsd:string">Red Hat Linux</name>
<price xsi:type = "xsd:double">54.99</price>
<description xsi:type = "xsd:string">
Red Hat Linux Operating System
</description>
<SKU xsi:type = "xsd:string">A358185</SKU>
</return>
</ns1:getProductResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
SOAP Transport
SOAP requests are sent via an HTTP POST request and SOAP responses are returned within the content of the HTTP GET response which require to set their content type to text/xml.The SOAP specification mandates that the client must provide a SOAPAction header, but the actual value of the SOAPAction header is dependent on the SOAP server implementation.
For example, to get the session service, hosted by XMethods, you must specify the following as a SOAPAction header.
REQUEST
RESPONSE
POST /perl/soaplite.cgi HTTP/1.0
Host: services.xmethods.com
Content-Type: text/xml; charset = utf-8
Content-Length: 538
SOAPAction: "urn:xmethods...#..."
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:api="http://api.---.com/">
<soapenv:Header/>
<soapenv:Body>
<api:login>
<!--Optional:-->
<api:username>xyz@org.com</api:username>
<!--Optional:-->
<api:password>password#</api:password>
<api:entityName>SYMJP</api:entityName>
</api:login>
</soapenv:Body>
</soapenv:Envelope>
HTTP/1.1 200 OK
Date: Sat, 09 Jun 2018 15:01:55 GMT
Server: Apache/1.3.14 (Unix) tomcat/1.0 PHP/4.0.1pl2
SOAPServer: SOAP::Lite/Perl/0.50
Cache-Control: s-maxage = 60, proxy-revalidate
Content-Length: 539
Content-Type: text/xml
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns1:loginResponse xmlns:ns1="http://api......com/">
<ns1:result>
<ns1:Session>3yrW4sAJnUbVFFKJe8C4M6j7LgPQQO59OSQF8Dc6WzqmbsKLhvxUeBsFXayujtQ1vRC5-P8JmFjTb-seRJE1s3gRaPmIbbuVckfUrCoxkg80sb7CqPl3wwGJezyJ2cti6ITTvpHHNhGdxMv15ROPFcq5_RNDW96Q2zYWYBnUn8EccyCtI1oQIiRHvTI3Mr9sMl77sD91NWS--pYwRmRkeT7SpYGWxOL0VDiD0pN2WzyvChW6s4HM6skIZyoMYHqTwpZ0ZAGF8nXEqUTKXe8q7Gs0rLqMFdET-KGMVCQhr8UxbihvGC_RPW1RTyvMoMAGfoYgyPBEUjMrnr0SXj98fK4E63vdR7mh04CYYeXzmC4=</ns1:Session>
<ns1:ServerUrl>https://apisandbox......com/apps/services/a/89.0</ns1:ServerUrl>
</ns1:result>
</ns1:loginResponse>
</soapenv:Body>
</soapenv:Envelope>
No comments:
Post a Comment