Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Page 2 of 6
Read the whole series on SOAP:
As I mentioned above, SOAP uses XML as the data-encoding format. The idea of using XML is not original to SOAP and is actually quite intuitive. XML-RPC and ebXML use XML as well. See Resources for references to Websites where you can find more information.
Consider the following Java interface:
Listing 1
public interface Hello
{
public String sayHelloTo(String name);
}
A client calling the sayHelloTo() method with a name would expect to receive a personalized "Hello" message from the server. Now imagine that RMI, CORBA, and
DCOM do not exist yet and it is up to you to serialize the method call and send it to the remote machine. Almost all of you
would say, "Let's use XML," and I agree. Accordingly, let's come up with a request format to send to the server. Assuming
that we want to simulate the call sayHelloTo("John"), I propose the following:
Listing 2
<?xml version="1.0"?>
<Hello>
<sayHelloTo>
<name>John</name>
</sayHelloTo>
</Hello>
I've made the interface name the root node. I've also made the method and parameter names nodes as well. Now we must deliver
this request to the server. Instead of creating our own TCP/IP protocol, we'll defer to HTTP. So, the next step is to package
the request into the form of an HTTP POST request and send it to the server. I will go into the details of what is actually required to create this HTTP POST request in a later section of this article. For now let's just assume that it is created. The server receives the request,
decodes the XML, and sends the client a response, again in the form of XML. Assume that the response looks as follows:
Listing 3
<?xml version="1.0"?>
<Hello>
<sayHelloToResponse>
<message>Hello John, How are you?</message>
</sayHelloToResponse>
</Hello>
The root node is still the interface name Hello. But this time, instead of just the method name, the node name, sayHelloTo, is the method name plus the string Response. The client knows which method it called, and to find the response to that method it simply looks for an element with that
method name plus the string Response.
I have just introduced you to the roots of SOAP. Listing 4 shows how the same request is encoded in SOAP:
Listing 4
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="
http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="
http://www.w3.org/1999/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/1999/XMLSchema">
<SOAP-ENV:Header>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<ns1:sayHelloTo
xmlns:ns1="Hello"
SOAP-ENV:encodingStyle="
http://schemas.xmlsoap.org/soap/encoding/">
<name xsi:type="xsd:string">John</name>
</ns1:sayHelloTo>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Looks slightly more complicated, doesn't it? Actually it's similar to what we did before with a few enhancements added in
for extensibility. First, note how the SOAP document is neatly organized into an Envelope (the root node), a header section, and a body. The header section is used to encapsulate data that is not tied to a specific
method itself, but instead provides context knowledge, such as a transaction ID and security information. The body section
contains the method-specific information. In Listing 2, the homegrown XML only had a body section.