In the previous blog, we have introduced the WebService and the three major backend technologies of WebService.
This blog will introduce the following SOAP and WSDL formats. First, understand a thing from the appearance, and then continue to understand it through future practices. Hey, what does it mean to know people? In fact, learning is just like life. Many learning principles or methods come from life. Well, we don't feel deeply about our lives. We went straight to the topic of this blog. Soap is the format of WebService message transmission. When we run a program, we only see whether the running result meets our requirements. How is it actually executed? To capture authentic and realistic messages, we must use tools around us. In the previous blog, we introduced two tools for debugging and capturing messages. In fact, if WebService is developed in eclispe, you can directly see the message passing through eclispe. In eclispe, open the J2EE view: first, run the service: Then click the WebService-based browser: select the two methods on the WSDL page: WS: Click any function, as shown in the add method: click "Source". The following are sent and received messages:
By capturing soap messages, we can see the components of soap messages. A soap message is an envelope. Letter header, subject. Writing a letter, of course, can be left blank (the so-called title), and the subject must be there; otherwise, writing this letter will be meaningless.
Therefore, the SOAP message format is as follows::
The basic structure of the SOAP message in the code format is as follows:: <? XML version = "1.0"?>
<Soap: Envelope
Xmlns: Soap = "http://www.w3.org/2001/12/soap-envelope"
Soap: encodingstyle = "http://www.w3.org/2001/12/soap-encoding">
<Soap: Header>
...
...
</Soap: Header>
<Soap: Body>
...
...
<Soap: Fault>
...
...
</Soap: Fault>
</Soap: Body>
</Soap: envelope>
Some notes about soap messages:
- Soap messages must be encoded in XML.
- Soap messages must use the SOAP envelope namespace
- Soap messages must use the soap encoding namespace
- Soap messages cannot contain DTD references
- Soap messages cannot contain XML processing instructions
By observing the transmitted SOAP message, we can find that not only the transmitted message, but also the HTTP protocol information at the top of the message. The sent message is as follows: In the sent message, there is the destination host, the number of bytes transmitted Content-Length, the transfer type Content-Type, character encoding charsetpost/ns HTTP/1.1
Content-Type: text/XML; charset = "UTF-8" Host: 127.0.0.1: 8880
Connection: keep-alive
Content-Length: 240 the received message is as follows: In the received message, there is an accepted status such as success 200 (HTTP/1.1 200 OK). The encoding format of HTTP transmission is transfer-encoding, transfer Type content-typehttp/1.1 200 OK
Transfer-encoding: chunked
Content-Type: text/XML; charset = "UTF-8" understand the SOAP format specification, which is much more convenient for coding. When using C ++ to access the WebService published by Java, It is a soap client written in the form of soap, and the service is also published on the Java Server. In post-blog posts, we will use the soap Writing Method to publish or access services. So now let's take a moment to learn about soap.