Bringing SOAP, Web Services, and .NET together
A Peek at SOAP
Briefly, Simple Object Access Protocol (SOAP) is a way to structure data so that any computer program in any language can read SOAP and send messages in SOAP.
If you're like me, you're impatient when it comes to new technologyyou want to know all the gritty details and the big picture all at once. To sate your appetite, I'll show you two example SOAP packets here, a request for data and a response to that request, but I won't go into any detail yet. That will have to wait until Chapter 2.
The classic SOAP example involves an application needing to know the latest stock price for a certain company. Your application sends a request for information to a remote computer that has the stock price information. That remote computer hears your request via SOAP, and returns the stock price. This type of interaction is known as request-response, and it's how the Web currently works (you ask a server for a Web page, and the server gives it to you).
Here's all the code for the two messages. Example 11 shows the request.
Example 11 Example SOAP request
<env:Envelope xmlns:env="http://www.w3.org/2001/06/soap-envelope"> <env:Body> <m:getStockPrice env:encodingStyle="http://www.w3.org/2001/06/ soap-encoding" xmlns:m="http://www.wire- man.com/services/stockquotes"> <symbol>PSFT</symbol> </m:getStockPrice> </env:Body> <env:Envelope>
Example 12 shows what the response might look like:
Example 12 Example of SOAP response
<env:Envelope xmlns:env="http://www.w3.org/2001/06/soap-envelope"> <env:Body> <m:getStockPriceResponse env:encodingStyle="http://www.w3.org/2001/06/ soap-encoding" xmlns:m="http://www.wire- man.com/services/stockquotes"> <price>45.89</price> </m:getStockPriceResponse> </env:Body> </env:Envelope>
These examples will have to hold you until the next chapter, when we dive headfirst into the details of SOAP. The rest of this chapter covers something more important: SOAP's place in the universewhy it exists and why you should care. Here's a preview: Many people think SOAP is the killer app of XML.