16.6 What's in kSOAP v2.0?The kSOAP v2.0 is based on the improved kXML pull parser. The pull parser could significantly improve the performance in some cases. Other important improvements of kSOAP v2.0 include the following:Access to SOAP headers: The SoapEnvelope object makes incoming and outgoing SOAP headers available in kDOM Element arrays.Better support for untyped SOAP servers: Some SOAP servers (notably, Microsoft .NET servers) do not bother to add the xsi:type= "xsd:string" attribute in string type elements. The kSOAP v2.0 SoapSerializationEnvelope provides a dotnet flag to turn on or off support for untyped elements.Better structure and packaging: Compared with kSOAP v1.0, the kSOAP v2.0 internal structure is more sensible and easier to use.- Necessary classes, such as PropertyInfo and KvmSerializable, are moved from org.kobjects to org.ksoap2 so that the kSOAP package is self-contained.- SOAP Serialization support is now optional and contained in a separate org.ksoap2.serialization package.- Several separate classes (e.g., ClassMap) have been integrated into the class SoapSerializationEnvelope, providing SOAP serialization support. The SoapSerializationEnvelope class extends the base class SoapEnvelope. 16.6.1 Programming for kSOAP v2.0From the developer point of view, the object models for SoapObject, PropertyInfo and Marshal in kSOAP v2.0 are the same as those in kSOAP v1.2. However, the call model is slightly different. In kSOAP v2.0, the call arguments and return values are passed as follows.The HttpTransport.call() method takes in a SoapEnvelope object but does not return any value.The bodyIn data member in the SoapEnvelope object is a SoapObject containing the RPC input argument.The marshaled result of the RPC return value is stored in SoapEnvelope.bodyOut. Depending on the return type and available Marshal, this could be a Java value object, an array or a SoapObject object. Listing 16.13 shows how to invoke the Google Web Service to get a spell suggestion using kSOAP v2.0. Please note the use of bodyIn and bodyOut variables. Listing 16.13. Get Google spell suggestion using kSOAP 2
The use of custom data marshal in kSOAP v2.0 is the same as that in kSOAP v1.2. Listing 16.14 shows how to get a site's Google cache using custom Base64 marshaling. Listing 16.14. Get Google cache using kSOAP 2
Listing 16.15 shows the implementation of the kSOAP v2.0 MarshalBase64 class using the XmlPull API. Listing 16.15. The MarshalBase64 implementation in kSOAP 2
|