The SOAP Envelope
The SOAP Envelope, as serialized by .NET, is shown in Listing 4.1.
Listing 4.1 The .NET SOAP Envelope Encoding
<?xml version="1.0"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://tempuri.org/" xmlns:types="http://tempuri.org/encodedTypes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Header/> <soap:Body/> </soap:Envelope>
Serialization refers to the process of turning actual method parameter information at the time that the Web Service is invoked into a SOAP XML packet. In this case, you see only the namespaces associated with the XML. You'll see example parameters serialized throughout the remainder of this chapter. Here, though, the stage is set for deserialization. You see that the XML is framed according to the SOAP specification (the soap namespace) and encoded (data is serialized) using constructs outlined in the SOAP encoding schema (soapenc). The W3 Committee's XML Schema datatypes are also specified using the xsd and xsi namespaces (integers, floating-point values, strings, and so on). You'll find XML elements throughout the XML document identified using these namespaces as well as other Web Servicespecific namespace values.
The SOAP Envelope literally serves as a wrapper for the really important information. You might imagine the Envelope acting as a postal envelope that encloses a letter or other correspondence. But that analogy actually breaks down a bit because an envelope that you use to send something to Aunt Millie also requires an address and postage. The SOAP Envelope certainly doesn't require a stamp; more importantly, the SOAP Envelope doesn't specify an address.
Perhaps a better analogy is to think of the SOAP Envelope as if it were a three-ring binder that you stuff with papers and notes. Inside the binder you'll insert cardboard tab sheets to separate various groups of notes and information. The tab sheets in the SOAP binder's case are the Header and the Body, as well as any custom elements you might create.
SOAP encodingStyle Attribute
Returning to SOAP itself, one thing that you'll find missing from the .NET packet in Listing 4.1 is the soap:encodingStyle attribute. If this attribute were serialized within the Envelope tag, the contents of the XML document would be serialized according to the value associated with the attribute. In most cases, this would be according to the SOAP schema found at http://schemas.xmlsoap.org/soap/envelope/ (this URL would be the value of the attribute):
Some other value would indicate another serialization encoding, such as a different XML vocabulary for some or all of the XML packet, encryption of portions of the packet, or possibly some other serialization rule change.
The first beta of .NET did not allow you to choose the encoding style. However, versions of .NET from beta 2 onward do allow you to select the encoding style you prefer, and if you want to follow the SOAP specification to the letter, you can choose to apply the System.Web.Services.Protocols.SoapRpcService attribute to your remote method. The resulting SOAP packets will then fully comply with the SOAP specification.
Because the attribute is missing from the serialization, you really don't know much at all about the encoding style of the contents, at least as indicated by the SOAP XML that you see in Listing 4.1. It's the WSDL that actually tells you all you need to know, so the omission of the attribute at the .NET SOAP packet level is really by design rather than by error.
However, if you later modify the SOAP XML stream that .NET provides to you (a technique that you'll see in Chapter 6, "Web Services in ASP.NET"), you might need to add this attribute to convey the relevant encoding information to the recipient of the packet.
The SOAP Envelope, as you've learned, provides a wrapper for the SOAP information necessary to convey the Web Service information. Inside the Envelope, you'll find the Header and Body of the method call. Let's turn to those objects now, starting with the SOAP Header.