Java Reference
In-Depth Information
<familyName>Turing</familyName>
<givenName>Adam</givenName>
<father href="#P02" />
</nsp:Person>
<nsp:Person>
<familyName>Turing</familyName>
<givenName>Adam</givenName>
<father href="#P02" />
</nsp:Person>
Note
A simple alternative to SOAP is XML-RPC. An XML-RPC package for CLDC is recently available
from http://kxmlrpc.enhydra.org .
kSOAP
The kSOAP API, available at http://www.ksoap.org , contains a kXML-based implementation of the
SOAP protocol and serialization format for CLDC. Because CLDC doesn't provide reflection
capabilities, existing classes must implement the interface KvmSerializable to add SOAP
serialization capabilities. kSOAP already includes serialization support for primitive types and
Vector s. KvmSerializable objects must be registered with a ClassMap object, providing a
mapping between XML namespaces and names and Java classnames. For classes that are needed in the
SOAP call only, you can use the convenience class SoapObject .
Listing 10.7 shows an example MIDlet for querying delayed stock quotes, corresponding to the request
and response code given in Listings 10.5 and 10.6 . The SOAP call is performed in the
commandAction() method. First, the SoapObject rpc is created, modeling the method object
getQuote . Then the symbol property is added. The symbol name is retrieved from the
corresponding UI field. Finally, an HttpTransport object is created, and the remote method
invocation is performed by the call() method with the rpc object as a parameter. The returned
value is displayed in the resultItem . Figure 10.2 shows the StockQuoteDemo MIDlet.
Figure 10.2. The StockQuoteDemo MIDlet.
Listing 10.7 StockQuoteDemo.java —A Stock Quote MIDlet Using kSOAP
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.io.*;
import javax.microedition.io.*;
import org.ksoap.*;
import org.ksoap.transport.HttpTransport;
 
 
Search WWH ::




Custom Search