From The Editor
by WDN, February 8, 2001
Deliver Mobile Services Using XML And SOAP
A year ago, I wrote about the potential for XML to revolutionize mobile
application development. One of the reasons is because mobile applications present the ultimate distributed computing environment: the clients
run a multitude of operating systems and can be located just about anywhere. Despite these restrictions, they all need to interact with servers to obtain
or update data. For the majority of applications, it is my opinion that technologies such as CORBA, DCOM, and Java RMI are now poor choices for basic remote
procedure calls and data interchange. Why build a server application and worry about operating systems, proprietary calling methods, and ORBs when open, XML-based technologies such as XML-RPC
and SOAP exist? XML levels the playing field and is serving to usher in a new generation of programmable
Web services.
Object-based distributed computing technologies (such as the afore-mentioned Java RMI, DCOM, and CORBA) rely on a piece of software known as an Object
Request Broker (or ORB). If you're running Microsoft Windows 2000 and have the
Java 2 Runtime Environment installed on your machine, you have installed DCOM, CORBA, and Java RMI ORBs...perhaps
unknowingly! Of course, each of these ORBs only interoperates with other ORBs that speak its own proprietary lingo which makes it awfully difficult
to build one service that can be accessed by anyone. Because ORBs are the ultimate thick clients, they also don't necessarily
make sense for a storage and processing-constrained device such as a PalmOS or Symbian handheld. Add in the fact that many firewalls block CORBA or DCOM
message passing, and you're faced with a tough situation if you're seeking to build an open service. Fortunately, XML-RPC and its offspring, SOAP, were
designed to solve this very problem. (Some props: XML-RPC was developed by UserLand Software while SOAP was
jointly developed by UserLand, Microsoft, DevelopMentor, and IBM.)
Two recently introduced products available for the Java 2 Micro Edition (J2ME) and Microsoft Windows CE platforms make XML and SOAP on handheld products
a reality. The first of these products is the open source kXML parser for J2ME, a project led by Stefan Haustein.
kXML is designed to run in a MIDP
environment (one of which is the PalmOS since Sun has now released a MIDP implementation for the Palm Computing Platform). kXML is a "pull-based" XML
parser, which basically means that the developer must loop through the XML document tree to "pull" the necessary elements out. Also included is support for
WBXML parsing and a SOAP API (to be named kSOAP is in the works). J2ME provides for local data storage access through its Record Management System
(and the associated javax.microedition.rms package) but unfortunately doesn't provide any serialization/reflection capabilities. Still, it is possible to retrieve
an XML stream from a server and roll your own XML serialization using kXML and the J2ME RMS. The following code snippet illustrates how kXML
can be used to parse a document (special thanks to Keith Bigelow and Lutris for giving me some pointers!):
|
try {
c = (StreamConnection)Connector.open("http://www.yourserver.com/file.xml");
s = c.openInputStream();
DefaultParser parser = new DefaultParser(new InputStreamReader(s));
Document document = new Document();
document.parse(parser);
Element root = document.getRootElement();
int count = root.getChildCount();
for (int i=0; i < count; i++) {
if (root.getType(i) == Xml.ELEMENT) {
Element l = root.getElement(i);
System.out.println("Element Name=" + l.getName());
}
}
}
catch (IOException err) {
System.out.println(err);
err.printStackTrace();
}
|
Another recently announced XML/SOAP tool is PocketSOAP for Windows CE. PocketSOAP is the result of the efforts of
Simon Fell. According to Simon, the PocketSOAP client can call other SOAP servers implemented using
4s4c, ROPE,
Apache SOAP, SOAP::Lite,
DM's SOAP/Perl and the XMethods soap Server.
The following code illustrates the use of PocketSOAP to issue a SOAP request to a server (Note: this code is shamelessly lifted from
this page...I'm not a Windows CE coder):
|
Function Test4s4c()
dim soap, t
set soap = CreateObject("PocketSOAP.Envelope")
soap.methodName = "Add"
soap.URI = "http://simon.fell.com/calc"
soap.CreateParameter "a", 100, "xsd:int"
soap.CreateParameter "b", 20, "xsd:int"
set t = CreateObject("PocketSOAP.HTTPTransport")
t.Send "http://www.razorsoft.net/ssss4c/soap.asp", soap.serialize
soap.parse t.Receive
' jump into the return parameters collection to get the results
wscript.echo "4s4c at www.razorsoft.net result (expecting 120) : " & _
soap.Parameters.ItemByName("added").Value
end Function
|
Are you a believer in SOAP and XML on mobile clients? Know of any additional projects that will be of interest to the WirelessDevNet audience?
If so, send WDN an email!.