WebReference.com - Part 3 of Chapter 3: Professional XML Web Services, from Wrox Press Ltd (1/5)
Professional XML Web Services
[The following is the last in a series of excerpts from Chapter 3 of the Wrox Press title, Professional XML Web Services. Ed.]
Once we have a SOAP message, we will probably want to send it to someone. After all, what good is a message if it never goes anywhere? The transport is the method by which a SOAP message is moved from sender to receiver. One example of a transport is HTTP, the Hypertext Transfer Protocol.
Separation of Message and Transport
One of the best design decisions made by the authors of SOAP was to separate the message definition from the message transport. It may sound ridiculous, but there is nothing in the specification that requires computers be involved in the transport of a SOAP message. Given that, here is a list of possible transports for SOAP messages (some more likely than others):
- Raw sockets
- Named Pipes
- Carrier Pigeon
Granted, not many developers will be exercising stock options after developing SOAP-enabled carrier pigeons, but this helps to illustrate the modular nature of the specification. Most developers are going to focus on HTTP as the standard transport for their SOAP messages, and that is the transport that we will focus on in this chapter. As SOAP support continues to grow, there will be SOAP transport bindings defined and implemented for any number of protocols.
When many developers think of SOAP, they think of XML over HTTP. HTTP is an excellent transport for SOAP because of its wide acceptance. HTTP is the ubiquitous protocol for the Web, a constant reminder that standards can actually work. Combining HTTP, the standard transport protocol for the Web, and SOAP, the leading candidate for the standard messaging format, gives us a powerful tool. HTTP makes such a great transport for SOAP that the authors made sure that the rules for using HTTP as a transport are part of the SOAP specification.
There are only a couple of basic rules for using HTTP as a SOAP transport. The mechanism for sending a SOAP message over HTTP is the standard HTTP POST method. An HTTP POST sends a block of data to a particular URI on the web server. In the case of SOAP messages, this block of data is the SOAP message itself. Because the SOAP message is XML, the Content-Type header of the HTTP POST must be
text/xml. If there is a response to the message, it is returned in the HTTP response.
Let's take another look at the example SOAP message we used earlier, this time transporting the message over HTTP.
POST /endpoint.asp HTTP/1.1 Content-Type: text/xml Content-Length: ### SOAPAction: "urn:wroxheroes" <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://schemas.xmlsoap.org/soap /encoding/"> <soap:Header> <h:from xmlns:h="http://www.wrox.com/Header"> SoapGuy@wrox.com </h:from> </soap:Header> <soap:Body> <w:GetSecretIdentity xmlns:w="http://www.wrox.com/heroes/"> <codename>XSLT-Man</codename> </w:GetSecretIdentity> </soap:Body> </soap:Envelope>
The first four lines of this example are related to the HTTP transport. The first line
contains the HTTP method,
POST, and the URI indicating the location of the endpoint. This
example might represent a SOAP message request sent to the URL http://www.wrox.com/endpoint.asp. The
first line also indicates that version 1.1 of HTTP is being used in this request.
The next three lines are the HTTP headers. The first two are standard HTTP.
Content-Type indicates the MIME type of the POST content. All SOAP messages must use
Content-Length tells the size in bytes of the content. The last
SOAPAction, is SOAP specific. We will examine that next, but before that, notice
the remainder of the HTTP request. There is an additional carriage-return/line feed that separates
headers from the body, and the body content itself is a SOAP message. The message itself does not
change because it is being transported by HTTP, and other than the
HTTP does not change just because it is sending a SOAP message.
Created: November 26, 2001
Revised: November 26, 2001