SOAP – Quick Guide ”; Previous Next What is SOAP? SOAP is an acronym for Simple Object Access Protocol. It is an XML-based messaging protocol for exchanging information among computers. SOAP is an application of the XML specification. Points to Note SOAP is a communication protocol designed to communicate via Internet. SOAP can extend HTTP for XML messaging. SOAP provides data transport for Web services. SOAP can exchange complete documents or call a remote procedure. SOAP can be used for broadcasting a message. SOAP is platform- and language-independent. SOAP is the XML way of defining what information is sent and how. SOAP enables client applications to easily connect to remote services and invoke remote methods. Although SOAP can be used in a variety of messaging systems and can be delivered via a variety of transport protocols, the initial focus of SOAP is remote procedure calls transported via HTTP. Other frameworks including CORBA, DCOM, and Java RMI provide similar functionality to SOAP, but SOAP messages are written entirely in XML and are therefore uniquely platform- and language-independent. SOAP – Message Structure A 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. 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. All these elements are declared in the default namespace for the SOAP envelope − http://www.w3.org/2001/12/soap-envelope and the default namespace for SOAP encoding and data types is − http://www.w3.org/2001/12/soap-encoding NOTE − All these specifications are subject to change. So keep updating yourself with the latest specifications available on the W3 website. SOAP Message Structure The following block depicts the general structure of a SOAP message − <?xml version = “1.0”?> <SOAP-ENV:Envelope xmlns:SOAP-ENV = “http://www.w3.org/2001/12/soap-envelope” SOAP-ENV:encodingStyle = “http://www.w3.org/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 The SOAP envelope indicates the start and the end of the message so that the receiver knows when an entire message has been received. The SOAP envelope solves the problem of knowing when you are done receiving a message and are ready to process it. The SOAP envelope is therefore basically a packaging mechanism. Points to Note Every SOAP message has a root Envelope element. Envelope is a mandatory part of SOAP message. 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. The envelope changes when SOAP versions change. The SOAP envelope is specified using the ENV namespace prefix and the Envelope element. The optional SOAP encoding is also specified using a namespace name and the optional encodingStyle element, which could also point to an encoding style other than the SOAP one. A v1.1-compliant SOAP processor generates a fault upon receiving a message containing the v1.2 envelope namespace. A v1.2-compliant SOAP processor generates a VersionMismatch fault if it receives a message that does not include the v1.2 envelope namespace. v1.2-Compliant SOAP Message Given below is an example of v1.2-compliant SOAP message. <?xml version = “1.0”?> <SOAP-ENV:Envelope xmlns:SOAP-ENV = “http://www.w3.org/2001/12/soap-envelope” SOAP-ENV:encodingStyle = ” http://www.w3.org/2001/12/soap-encoding”> … Message information goes here … </SOAP-ENV:Envelope> SOAP with HTTP POST The following example illustrates the use of a SOAP message within an HTTP POST operation, which sends the message to the server. It shows the namespaces for the envelope schema definition and for the schema definition of the encoding rules. The OrderEntry reference in the HTTP header is the name of the program to be invoked at the tutorialspoint.com website. POST /OrderEntry HTTP/1.1 Host: www.tutorialspoint.com Content-Type: application/soap; charset = “utf-8” Content-Length: nnnn <?xml version = “1.0”?> <SOAP-ENV:Envelope xmlns:SOAP-ENV = “http://www.w3.org/2001/12/soap-envelope” SOAP-ENV:encodingStyle = ” http://www.w3.org/2001/12/soap-encoding”> … Message information goes here … </SOAP-ENV:Envelope> NOTE − The HTTP binding specifies the location of the service. SOAP – Header The optional Header element offers a flexible framework for specifying additional application-level requirements. For example, the Header element can be used to specify a digital signature for password-protected services. Likewise, it can be used to specify an account number for pay-per-use SOAP services. Points to Note It is an optional part of a SOAP message. Header elements can occur multiple times. Headers are intended to add new features and functionality. The SOAP header contains header entries defined in a namespace. The header is encoded as the first immediate child element of the SOAP envelope. When multiple headers are defined, all immediate child elements of the SOAP header are interpreted as SOAP header blocks. SOAP Header Attributes A SOAP Header can have the following two 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. The following example shows how to use a Header in a SOAP message. <?xml version = “1.0”?> <SOAP-ENV:Envelope xmlns:SOAP-ENV = ” http://www.w3.org/2001/12/soap-envelope” SOAP-ENV:encodingStyle = ” http://www.w3.org/2001/12/soap-encoding”> <SOAP-ENV:Header> <t:Transaction xmlns:t = “http://www.tutorialspoint.com/transaction/” SOAP-ENV:mustUnderstand = “true”>5 </t:Transaction> </SOAP-ENV:Header> … … </SOAP-ENV:Envelope> SOAP – Body The SOAP body is a mandatory element that contains the application-defined XML data being exchanged in the SOAP message. The body must be contained within the envelope and must follow any headers that might be defined for the message. The body
Category: soap
SOAP – Envelope
SOAP – Envelope ”; Previous Next The SOAP envelope indicates the start and the end of the message so that the receiver knows when an entire message has been received. The SOAP envelope solves the problem of knowing when you are done receiving a message and are ready to process it. The SOAP envelope is therefore basically a packaging mechanism. Points to Note Every SOAP message has a root Envelope element. Envelope is a mandatory part of SOAP message. 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. The envelope changes when SOAP versions change. The SOAP envelope is specified using the ENV namespace prefix and the Envelope element. The optional SOAP encoding is also specified using a namespace name and the optional encodingStyle element, which could also point to an encoding style other than the SOAP one. A v1.1-compliant SOAP processor generates a fault upon receiving a message containing the v1.2 envelope namespace. A v1.2-compliant SOAP processor generates a VersionMismatch fault if it receives a message that does not include the v1.2 envelope namespace. v1.2-Compliant SOAP Message Given below is an example of v1.2-compliant SOAP message. <?xml version = “1.0”?> <SOAP-ENV:Envelope xmlns:SOAP-ENV = “http://www.w3.org/2001/12/soap-envelope” SOAP-ENV:encodingStyle = ” http://www.w3.org/2001/12/soap-encoding”> … Message information goes here … </SOAP-ENV:Envelope> SOAP with HTTP POST The following example illustrates the use of a SOAP message within an HTTP POST operation, which sends the message to the server. It shows the namespaces for the envelope schema definition and for the schema definition of the encoding rules. The OrderEntry reference in the HTTP header is the name of the program to be invoked at the tutorialspoint.com website. POST /OrderEntry HTTP/1.1 Host: www.tutorialspoint.com Content-Type: application/soap; charset=”utf-8″ Content-Length: nnnn <?xml version = “1.0”?> <SOAP-ENV:Envelope xmlns:SOAP-ENV = “http://www.w3.org/2001/12/soap-envelope” SOAP-ENV:encodingStyle = ” http://www.w3.org/2001/12/soap-encoding”> … Message information goes here … </SOAP-ENV:Envelope> NOTE − The HTTP binding specifies the location of the service. Print Page Previous Next Advertisements ”;
SOAP – Body
SOAP – Body ”; Previous Next The SOAP body is a mandatory element that contains the application-defined XML data being exchanged in the SOAP message. The body must be contained within the envelope and must follow any headers that might be defined for the message. The body is defined as a child element of the envelope, and the semantics for the body are defined in the associated SOAP schema. The body contains mandatory information intended for the ultimate receiver of the message. For example − <?xml version = “1.0”?> <SOAP-ENV:Envelope> …….. <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> The example above requests a quotation of computer sets. Note that the m:GetQuotation and the Item elements above are application-specific elements. They are not a part of the SOAP standard. Here is the response to the above query − <?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> Normally, the application also defines a schema to contain semantics associated with the request and response elements. 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. The SOAP processor could also be mapping the body information to a .NET object, a CORBA object, a COBOL program, and so on. Print Page Previous Next Advertisements ”;
SOAP – Header
SOAP – Header ”; Previous Next The optional Header element offers a flexible framework for specifying additional application-level requirements. For example, the Header element can be used to specify a digital signature for password-protected services. Likewise, it can be used to specify an account number for pay-per-use SOAP services. Points to Note It is an optional part of a SOAP message. Header elements can occur multiple times. Headers are intended to add new features and functionality. The SOAP header contains header entries defined in a namespace. The header is encoded as the first immediate child element of the SOAP envelope. When multiple headers are defined, all immediate child elements of the SOAP header are interpreted as SOAP header blocks. SOAP Header Attributes A SOAP Header can have the following two 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. The following example shows how to use a Header in a SOAP message. <?xml version = “1.0”?> <SOAP-ENV:Envelope xmlns:SOAP-ENV = ” http://www.w3.org/2001/12/soap-envelope” SOAP-ENV:encodingStyle = ” http://www.w3.org/2001/12/soap-encoding”> <SOAP-ENV:Header> <t:Transaction xmlns:t = “http://www.tutorialspoint.com/transaction/” SOAP-ENV:mustUnderstand = “true”>5 </t:Transaction> </SOAP-ENV:Header> … … </SOAP-ENV:Envelope> Print Page Previous Next Advertisements ”;