Introduction to soap

Source: Internet
Author: User
Tags xml parser

Introduction to soap

Soap-Simple Object Access Protocol ). Soap is a lightweight, simple, XML-based protocol designed to exchange structured and solidified information on the Web. Soap can be used in combination with many existing Internet protocols and formats, including Hypertext Transfer Protocol (HTTP), Simple Mail Transfer Protocol (SMTP), and multi-purpose Internet Mail Extension protocol (MIME ). It also supports a large number of applications from the message system to Remote Process calling (RPC.
Soap provides a simple lightweight mechanism for exchanging structured and typed information with XML in a loose and distributed environment. Soap itself does not define any application semantics, such as programming models or specific semantic implementations. It only defines a simple mechanism, the application semantics is represented by a modular packaging model and a data re-indexing mechanism for specific format encoding in the module. This capability of SOAP allows many types of systems to extend from message systems to Remote Procedure Calls.
Currently, W3C has released the soap1.2 standard, but soap1.1 is widely used.
Soap V1.1: http://www.w3.org/TR/2000/NOTE-SOAP-20000508/
Soap v1.2: http://www.w3.org/TR/2001/WD-soap12-20010709/
 

The SOAP specification consists of four parts:
L SOAP envelope (envelop), which defines a SOAP message representation framework that describes the content of a message, who sends the message, and who should process and process it, and whether these operations are optional or required.
L The soap encoding rule (encoding rules) defines a data encoding mechanism, and defines the data types to be used in applications through such a compaction mechanism, it can also be used to exchange instances derived from the data types defined by these applications. For example, the data type of the order may be defined by using soap encoding rules, and the order instance can be exchanged between the client generated by the order and the Order Service.
L RPC representation defines a convention for expressing remote process calls and responses, for example, how to use HTTP or SMTP protocol to bind with soap and how to transmit process calls, in which part of the specific transmission protocol transmits the process response. For example, we can transmit the process response in the HTTP response.
L soap binding defines a convention that uses the underlying transport protocol to exchange soap envelopes between nodes.
To simplify this specification, these four parts are functionally orthogonal. In particular, envelope and encoding rules are defined in different namespaces, which facilitates simplification through modularity.
The specification also defines two types of soap binding, which is used to describe how a SOAP message uses the HTTP extension framework [6] (HTTP extension framework) with or without the HTTP extension framework) HTTP [5] Message for transmission.
Soap messages are basically unidirectional transmission from the sending end to the receiving end, but they are often combined to execute a mode similar to request/response. All soap messages are encoded in XML format. A soap message is an XML file that contains an essential soap encapsulation package, an optional SOAP header, and a required soap block.
Shows the SOAP Message Components:

 

Figure 1.1 SOAP Message Components
The XML part of a SOAP request consists of three main parts:
L envelope defines the namespaces that will be used for the rest of each SOAP message, typical include xmlns: SOAP-ENV (SOAP envelope namespace), xmlns: xsi (XML schema for instances) and xmlns: XSD (XML schema for datatypes ).
L header is an optional element that carries the auxiliary information for authentication, transaction processing, and payment. Any element in a soap processing chain can add or delete items in the header. elements can also choose to ignore items they do not know. If the header is used, it must be the first child element of envelope.
L body is the main effective carrier of messages. When soap is used to execute an RPC call, the body contains a separate element that contains the method name, parameters, and target address of the web service. The namespace of the element is equal to the target address, and the root name is the method name.


In HTTP, soaphttp-Hypertext Transfer protocol is used to transmit all the communications on WWW (World Wide Web. HTTP is a client-server model: the client submits a request to the server, and then the server sends a response. As HTTP is simple, stable, and widely used, and most firewalls are open to port 80 of the HTTP protocol, HTTP is the most popular protocol in the service transport layer.
Binding soap to HTTP provides the advantages of using soap styles, scattered flexibility, and HTTP's rich feature libraries. Transmitting soap over HTTP does not mean that soap will overwrite the existing HTTP semantics, but that the soap semantics on HTTP will naturally map to the HTTP semantics. When HTTP is used as the Protocol binding, RPC requests are mapped to HTTP requests, while RPC responses are mapped to HTTP responses. However, using soap on RPC is not limited to HTTP binding.
The Content-Type header of the HTTP request and response message must be set to text/XML (Application/soap + XML in soap 1.2 ). For a request message, it must use post as a verb, and Uri should recognize the soap processor. The SOAP specification also defines a new HTTP header named soapaction. All soap HTTP requests (even empty) must contain this header. The soapaction header is designed to indicate the intent of the message. For an HTTP response, if no error occurs, it should use the 200 status code. if it contains a soap error, it should use 500.
 

The following is an example of binding HTTP to soap. In this example, a getlasttradeprice SOAP request is sent to a stackquote service, which accepts a string parameter, namely, the buzzer symbol, in the soap response, a floating point number is returned, that is, the price. The soap envelop element is the top-level element of the XML document that represents the SOAP message. The XML namespace is used to eliminate the ambiguity between application-related identifiers and soap identifiers.
Example 1 SOAP message nested in an HTTP request
Post or stockquote HTTP/1.1
HOST: www.stockquoteserver.com
Content-Type: text/XML; charset = "UTF-8"
Content-Length: NNNN
Soapaction: "Some-Uri"

<SOAP-ENV: Envelope
Xmlns: SOAP-ENV = "http://schemas.xmlsoap.org/soap/envelope"
SOAP-ENV: encodingstyle = "http://schemas.xmlsoap.org/soap/encoding/">
SOAP-ENV: Body>
<M: getlasttradeprice xmlns: M = "Some-Uri">
<Symbol> dis </symbol>
</M: getlasttradeprice>
SOAP-ENV: Body>
SOAP-ENV: envelope>
 

Example 2 soap messages nested in HTTP responses
HTTP/1.1 200 OK
Content-Type: text/XML; charset = "UTF-8"
Content-Length: NNNN

<SOAP-ENV: Envelope
Xmlns: SOAP-ENV = "http://schemas.xmlsoap.org/soap/envelope"
SOAP-ENV: encodingstyle = "http://schemas.xmlsoap.org/soap/encoding/"/>
SOAP-ENV: Body>
<M: getlasttradepriceresponse xmlns: M = "Some-Uri">
<Price> 34.5 </price>
</M: getlasttradepriceresponse>
SOAP-ENV: Body>
SOAP-ENV: envelope>

Web Service

On the surface, Web Service is an application that exposes an API that can be called through the Web. That is to say, you can use a programming method to call this application through the Web. We call the Web service application a customer.
From a deeper perspective, Web Service is a new Web application branch. It is a self-contained, self-described, and modular application that can be deployed on the Network (usually Web) is described, published, searched, and called through the Web.
Web Service is a network-based, distributed modular component that executes specific tasks and complies with specific technical specifications. These specifications Enable Web service to interoperate with other compatible components. It can use standard Internet protocols, such as hypertext transfer protocol HTTP and XML, to embody functions on the Internet and the enterprise intranet. The Web service platform is a set of standards that define how applications implement interoperability on the web. You can use any language you like to write Web Services on any platform you like.
More accurate explanation of Web Services: Web Services is a new platform for building interoperable distributed applications. The Web service platform is a set of standards that define how applications implement interoperability on the web. You can use any language you like to write Web Services on any platform you like, as long as we can query and access these services through web service standards.
Three basic web service technologies
L Web Service publishes useful program modules (in service mode) on the Internet through standard communication protocols. At present, most of them use soap for communication protocols.
L Web Service provides a detailed interface description to help users build applications. This interface description is called Web Service Description Language (WSDL ).
L usually published web services must be registered to the management server, which is convenient for users to query and use. This is done through UDDI (Universal discovery description and integration.
 

Soap is an XML-based presentation layer protocol that does not rely on the Transport Protocol (see the ISO 7 Reference Model. TCP/IP is roughly equivalent to the transport layer and network layer, and HTTP is equivalent to the Session Layer ), it is used to easily exchange data between applications in the form of objects.
In the lower layer of soap, it can be HTTP/HTTPS (most used now), SMTP/POP3, or special communication protocol specially designed for some applications.
The soap application system can work in two modes: Remote Procedure Call and document oriented in Microsoft documents, in Apache documents, it is called message-oriented, which is an application that can use XML to exchange more complex structural data. Moreover, it is potentially applicable to B2B transaction processing and other fields. In this article, we will focus on rpc. For the latter, I hope I can introduce it to you in future articles. The RPC computing architecture is shown in Figure 1.2.

 

Figure 1.2 RPC Computing Architecture Model
As shown in Figure 1.2, soap RPC works very similar to the Web Request/response method, instead of using XML that complies with the soap specifications to replace HTML, HTTP is a stateless protocol, but today, session-based state management is a well-known technology. Stateless protocols are very suitable for loosely coupled systems, it also has potential advantages and contributions to load balancing and other issues.
(1) The customer program creates an XML document that contains the URI for providing services, the method name and parameter information for client request calls. If the parameter is an object, serialization is required.
(2) the target server receives the XML document sent by the client program and performs alignment parsing. If the parameter is an object, deserialize it and then execute the client request method.
(3) After the method is executed on the target server, if the returned value of the method is an object, the serialization operation is performed, and then the return value is returned to the customer in the form of an XML document.
(4) The client program receives the XML document sent from the server. If the returned value is an object, it first performs deserialization and finally obtains the returned value.
 

XML Parser refers to the XML parser, And the DOM (Document Object Model) interface refers to the Document Object Model interface.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.