Welcome!

Microservices Expo Authors: Derek Weeks, Liz McMillan, Elizabeth White, John Katrick, Pat Romanski

Related Topics: Microservices Expo

Microservices Expo: Article

Wireless Web Serviceswith J2ME Part IISOAP or XML-RPC? The answer depends on your needs

Wireless Web Serviceswith J2ME Part IISOAP or XML-RPC? The answer depends on your needs

Last month in Part I (WSJ Vol. 2 Issue 1) we discussed J2ME and accessing Web services from wireless devices using the XML-RPC protocol. In this article, we will consider SOAP as a vehicle for accessing Web services from wireless devices, comparing and contrast-ing it with XML-RPC. Our sample application will again be a J2ME midlet, however, we will use EnhydraME's kSOAP rather than kXML-RPC to provide the protocol's implementation.

Overview of SOAP
The Simple Object Access Protocol is, according to the 1.1 specification, "a lightweight protocol for exchange of information in a decentralized, distributed environment." The protocol is entirely based on XML, vendor-neutral, and one of the cornerstone technologies in the Web services revolution. It is quite similar to XML-RPC, but we will examine that more closely in the next section.

SOAP was originally conceived and developed at Microsoft between 1998 and 1999. SOAP did not, however, gain widespread attention until DevelopMentor, IBM, Lotus, and Microsoft submitted the SOAP 1.1 version to the W3C on April 26, 2000. With both IBM and Microsoft behind it, the industry began to give SOAP some serious consideration. As of this writing, the SOAP 1.2 specification is being drafted by the W3C's XML Protocol Working Group. The latest draft of the 1.2 spec can be found at www.w3.org/TR/soap12/.

When examining SOAP, it is important to identify the three main components of any SOAP message: the SOAP envelope, rules for encoding data, and a request/response interaction mechanism. The SOAP messaging architecture can be compared to a postal system (see Figure 1). A document is enclosed in an envelope and that envelope is transmitted via the transport mechanism, the mail system in our analogy, or HTTP across a network in the case of SOAP. With the mail, a zip code identifies the locale an envelope should be delivered to; with SOAP, HTTP header data provides such routing information. At this point, the analogy breaks down. Whereas the "last mile service" provided by a postal carrier is directed by the street address on the envelope, it is information encoded in the body of the XML document itself that ultimately directs the SOAP request to the specific service on the server.

XML-RPC vs SOAP
Although SOAP and XML-RPC have similar roots (XML-RPC is based on a subset of the original SOAP spec that was developed at Microsoft in the late 1990s), they are very different animals. Both XML-RPC and SOAP are XML-based protocols for communication and data exchange, so when should one be chosen over the other? We'll take a look at their strengths and weaknesses, and then evaluate these two protocols from a business perspective.

XML-RPC is an extremely lightweight mechanism for invoking XML-based services. It is a clean, simple protocol that provides the minimum overhead necessary to invoke remote services and exchange data in a platform-, language-, and vendor-neutral manner. It defines six simple data types and two complex types. The result is that XML-RPC is a highly-efficient lightweight protocol. Messages are simple to construct, simple to parse, simple to debug, and are easily human-readable. XML-RPC requires a minimal amount of active memory for processing, building, and parsing messages, and produces a thin message body to be exchanged between client and server.

In contrast, SOAP is a fatter protocol (although generally considered lightweight). In exchange for some additional overhead, SOAP provides namespace awareness, a sophisticated data-typing mechanism, and a flexible messaging paradigm. The W3C's XML Namespaces specification is leveraged to provide namespace awareness, and the XML Schema specification provides the data-typing mechanism. As such, SOAP supports over 40 standard data types and provides the capabilities to define custom simple and complex data types. This provides a tremendous degree of flexibility in terms of describing robust data structures with intricate relationships with other data contained in the message body.

The SOAP architecture also introduces a flexible messaging architecture, supporting a variety of messaging paradigms, including unidirectional, bidirectional, multicast (publish-subscribe), and sequentialmessaging (multiple parties chained together in a particular order). One aspect that facilitates these paradigms is the ability of a SOAP message to include a header section. This allows security, transaction, and routing information to be exchanged between multiple parties. For example, a client can send a SOAP request with an intended destination, but also declare in the SOAP envelope's headers that a particular party should receive the message, process the pertinent header information, and then pass the message on to the next party in the chain (or the intended recipient if no other parties have been declared). One final distinction is that SOAP supports asynchronous messaging, while XML-RPC requires a synchronous communication between the two parties in an exchange.

With all of these differences between the two protocols, executives, project managers, and wireless architects alike are wondering - "How do I make a choice between SOAP and XML-RPC for a particular wireless project or system?" Well, even if you weren't wondering that, we're going to tell you anyway.

In a nutshell, XML-RPC provides a fast, compact protocol for exchanging data and invoking services in a neutral, standardized way. If application size, memory, and bandwidth are your top priorities, then XML-RPC is the way to go. On the other hand, if your application requires a robust data-typing mechanism, extensive security or transaction support, or a flexible messaging architecture, then SOAP is your answer. Also, SOAP is more mainstream than XML-RPC, so if your application needs to access a variety of services that you have no control over, SOAP may be a better match from an interoperability perspective. To break it down into more detail, Table 1 that outlines the business justifications for using each protocol.

Wireless SOAP Example
In our previous article we developed a sample application using kXML-RPC (http://kxmlr pc.enhydra.org), an open-source implementation of the XML-RPC protocol for micro devices maintained by Enhydra. kSOAP (http://ksoap.enhydra.org) is another Enhydra Micro Edition project, providing SOAP support for mobile devices. We will create a MIDP interface with the kSOAP libraries underneath to activate a SOAP-based Web service located on a remote HTTP server.

For our application, we will be using three classes from the kSOAP library to handle the marshalling and unmarshalling of data via SOAP:

  • HttpTransport: A convenient API that enables SOAP calls via HTTP using the J2ME Generic Connection Framework
  • ClassMap: Provides namespace support and a two-way mapping between namespace-qualified XML names and Java classes
  • SoapObject: A generic object used to represent any SOAP object within the body of a SOAP request or response. SOAP objects can also be nested
Rather than creating both the client and the service we are accessing, we will simply access an existing service. Xmet hods.com provides a Web service registry for publicly available Web services. We will be invoking a service provided by Cape Clear that gathers and disseminates airport weather information on behalf of a client. The details regarding that service can be located at: www.xmethods.com/detail.html?id=129, and the source code for this midlet (Airport Weather.java) can be downloaded from the kSOAP Web site at http://ksoap.enhydra.org/software/downloads/index.html.

In creating our sample SOAP midlet (AirportWeather.java), the process is identical to the one we used in Part 1. This time, the packages and names have been changed to protect the innocent. We will import, extend, and use classes from the kSOAP library rather than the kXML-RPC library.

The first step, obviously, is to import the necessary packages and declare the MIDP components that will be used in the application. After this, we define the midlet's constructor, initializing all the UI components, and add them to the display as necessary. With that complete, we need to fill in the three other lifecycle methods. In the startApp() method, we simply bring the MIDP display into action. Since we don't use any shared resources, the pauseApp() method is blank. Finally, the destroyApp() method releases the local resources that we have allocated for our midlet.

As with Part 1, all the action takes place in the commandAction() method. This method is called anytime the user performs a command event (pressing a key, selecting an item from a list, etc.). The Command and Displayable objects are then queried to determine which component has actually been activated/ deactivated, and the appropriate actions are performed. When our midlet is launched, it displays a list of popular international airports for which weather information can be retrieved (see Figure 2). It also displays an exit button to allow the user to exit the midlet.

Upon selecting an airport, a list of weather information services for that airport is displayed (see Figure 3). A back button is also displayed to allow the user to return to the airport menu. The user then selects the weather information service he or she is interested in and the midlet sends a SOAP request to the server to collect the desired information. A SOAP response is returned, parsed by the midlet, and the result is displayed on the screen. So how does all of that work? See Listing 1 for the command Action() method.

The outer level of the commandAct ion() method checks to see what component has been activated. We'll look at each of these four events individually, beginning with the airport menu:

if ( dis == airportMenu && com == List.SELECT_COMMAND ) {
currentAirport = airportMenu.getSelectedIndex();
servicesMenu.setTitle( airports[ currentAirport ] + " weather" );
display.setCurrent( servicesMenu ); //display the list of services

When an airport is selected, we set the currentAirport variable, set the title for the services menu to reflect the selected airport, and display the services menu.

Next we'll look at the services menu. There are seven possible weather services that can be retrieved: wind conditions, temperature, pressure, humidity, sky conditions, visibility, and a complete summary containing the six individual pieces of information:

else if ( dis == servicesMenu && com == List.SELECT_COMMAND ) {
String result = null;
int choice = servicesMenu.getSelectedIndex();

The first thing to do is to declare a String variable to store the result of the service call that will be made. Next, determine which service has been selected and store the index value in an integer variable and perform a switch on that variable. The switch statement can be seen in Listing 2. The first case retrieves a summary and the other cases retrieve individual weather items. After the switch statement, the results are displayed on the screen via an Alert object.

Within each case statement in the switch block, the callSer vice() method is used to handle the exchange of SOAP messages. See Listing 3).

Four essential things take place in this method. An HttpTran sport object is created, a PrefixMap namespace is created for the SOAP envelope, a SoapObject is created to represent the request, and the request object is sent via the HttpTransport class's call() method.

The next else/if block checks to see if the back command has been selected, in which case the list of airports is displayed:

else if ( com == backCommand ) {
display.setCurrent( airportMenu );

Finally, the exit command is checked to allow the application to be exited:

else if ( com == exitCommand ) {
destroyApp( true );
notifyDestroyed();

That's all there is to it. Download the source code to get the details for the interface and then you are ready to build the midlet interface, compile the code and access this weather service from a J2ME phone using SOAP!

Conclusion
Web services are sweeping the industry and changing the face of business. Mobile computing and wireless access to information at any time, from anywhere, is an increasingly popular idea. The combination of the two is explosive! In these two articles, we've explored XML-RPC and SOAP as protocols for accessing Web services from wireless devices. XML-RPC provides a highly-efficient, extremely lightweight mechanism for invoking Web services that is ideal for mobile and embedded devices. SOAP provides a slightly heavier protocol with increased functionality and flexibility. Between these two, an appropriate protocol will likely be found for any wireless project.

More Stories By Kyle Gabhart

Kyle Gabhart is a subject matter expert specializing in strategic planning and tactical delivery of enterprise technology solutions, blending EA, BPM, SOA, Cloud Computing, and other emerging technologies. Kyle currently serves as a director for Web Age Solutions, a premier provider of technology education and mentoring. Since 2001 he has contributed extensively to the IT community as an author, speaker, consultant, and open source contributor.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@MicroservicesExpo Stories
Some people are directors, managers, and administrators. Others are disrupters. Eddie Webb (@edwardawebb) is an IT Disrupter for Software Development Platforms at Liberty Mutual and was a presenter at the 2016 All Day DevOps conference. His talk, Organically DevOps: Building Quality and Security into the Software Supply Chain at Liberty Mutual, looked at Liberty Mutual's transformation to Continuous Integration, Continuous Delivery, and DevOps. For a large, heavily regulated industry, this task...
Modern software design has fundamentally changed how we manage applications, causing many to turn to containers as the new virtual machine for resource management. As container adoption grows beyond stateless applications to stateful workloads, the need for persistent storage is foundational - something customers routinely cite as a top pain point. In his session at @DevOpsSummit at 21st Cloud Expo, Bill Borsari, Head of Systems Engineering at Datera, explored how organizations can reap the bene...
Kubernetes is an open source system for automating deployment, scaling, and management of containerized applications. Kubernetes was originally built by Google, leveraging years of experience with managing container workloads, and is now a Cloud Native Compute Foundation (CNCF) project. Kubernetes has been widely adopted by the community, supported on all major public and private cloud providers, and is gaining rapid adoption in enterprises. However, Kubernetes may seem intimidating and complex ...
Gaining visibility in today’s sprawling cloud infrastructure is complex and laborious, involving drilling down into tools offered by various cloud services providers. Enterprise IT organizations need smarter and effective tools at their disposal in order to address this pertinent problem. Gaining a 360 - degree view of the cloud costs requires collection and analysis of the cost data across all cloud infrastructures used inside an enterprise.
You know you need the cloud, but you’re hesitant to simply dump everything at Amazon since you know that not all workloads are suitable for cloud. You know that you want the kind of ease of use and scalability that you get with public cloud, but your applications are architected in a way that makes the public cloud a non-starter. You’re looking at private cloud solutions based on hyperconverged infrastructure, but you’re concerned with the limits inherent in those technologies.
Gone are the days when application development was the daunting task of the highly skilled developers backed with strong IT skills, low code application development has democratized app development and empowered a new generation of citizen developers. There was a time when app development was in the domain of people with complex coding and technical skills. We called these people by various names like programmers, coders, techies, and they usually worked in a world oblivious of the everyday pri...
Our work, both with clients and with tools, has lead us to wonder how it is that organizations are handling compliance issues in the cloud. The big cloud vendors offer compliance for their infrastructure, but the shared responsibility model requires that you take certain steps to meet compliance requirements. Which lead us to start poking around a little more. We wanted to get a picture of what was available, and how it was being used. There is a lot of fluidity in this space, as in all things ...
The dynamic nature of the cloud means that change is a constant when it comes to modern cloud-based infrastructure. Delivering modern applications to end users, therefore, is a constantly shifting challenge. Delivery automation helps IT Ops teams ensure that apps are providing an optimal end user experience over hybrid-cloud and multi-cloud environments, no matter what the current state of the infrastructure is. To employ a delivery automation strategy that reflects your business rules, making r...
The notion of improving operational efficiency is conspicuously absent from the healthcare debate - neither Obamacare nor the newly proposed GOP plan discusses the impact that a step-function improvement in efficiency could have on access to healthcare (through more capacity), quality of healthcare services (through reduced wait times for patients) or cost (through better utilization of scarce, expensive assets).
Admiral Calcote - also known as Lee Calcote (@lcalcote) or the Ginger Geek to his friends - gave a presentation entitled Characterizing and Contrasting Container Orchestrators at the 2016 All Day DevOps conference. Okay, he isn't really an admiral - nor does anyone call him that - but he used the title admiral to describe what container orchestrators do, relating it to an admiral directing a fleet of container ships. You could also say that they are like the conductor of an orchestra, directing...
Cloud Governance means many things to many people. Heck, just the word cloud means different things depending on who you are talking to. While definitions can vary, controlling access to cloud resources is invariably a central piece of any governance program. Enterprise cloud computing has transformed IT. Cloud computing decreases time-to-market, improves agility by allowing businesses to adapt quickly to changing market demands, and, ultimately, drives down costs.
For DevOps teams, the concepts behind service-oriented architecture (SOA) are nothing new. A style of software design initially made popular in the 1990s, SOA was an alternative to a monolithic application; essentially a collection of coarse-grained components that communicated with each other. Communication would involve either simple data passing or two or more services coordinating some activity. SOA served as a valid approach to solving many architectural problems faced by businesses, as app...
SYS-CON Events announced today that Synametrics Technologies will exhibit at SYS-CON's 22nd International Cloud Expo®, which will take place on June 5-7, 2018, at the Javits Center in New York, NY. Synametrics Technologies is a privately held company based in Plainsboro, New Jersey that has been providing solutions for the developer community since 1997. Based on the success of its initial product offerings such as WinSQL, Xeams, SynaMan and Syncrify, Synametrics continues to create and hone in...
Some journey to cloud on a mission, others, a deadline. Change management is useful when migrating to public, private or hybrid cloud environments in either case. For most, stakeholder engagement peaks during the planning and post migration phases of a project. Legacy engagements are fairly direct: projects follow a linear progression of activities (the “waterfall” approach) – change managers and application coders work from the same functional and technical requirements. Enablement and develo...
The “Digital Era” is forcing us to engage with new methods to build, operate and maintain applications. This transformation also implies an evolution to more and more intelligent applications to better engage with the customers, while creating significant market differentiators. In both cases, the cloud has become a key enabler to embrace this digital revolution. So, moving to the cloud is no longer the question; the new questions are HOW and WHEN. To make this equation even more complex, most ...
Recent survey done across top 500 fortune companies shows almost 70% of the CIO have either heard about IAC from their infrastructure head or they are on their way to implement IAC. Yet if you look under the hood while some level of automation has been done, most of the infrastructure is still managed in much tradition/legacy way. So, what is Infrastructure as Code? how do you determine if your IT infrastructure is truly automated?
Every few years, a disruptive force comes along that prompts us to reframe our understanding of what something means, or how it works. For years, the notion of what a computer is and how you make one went pretty much unchallenged. Then virtualization came along, followed by cloud computing, and most recently containers. Suddenly the old rules no longer seemed to apply, or at least they didn’t always apply. These disruptors made us reconsider our IT worldview.
As people view cloud as a preferred option to build IT systems, the size of the cloud-based system is getting bigger and more complex. As the system gets bigger, more people need to collaborate from design to management. As more people collaborate to create a bigger system, the need for a systematic approach to automate the process is required. Just as in software, cloud now needs DevOps. In this session, the audience can see how people can solve this issue with a visual model. Visual models ha...
Containers are rapidly finding their way into enterprise data centers, but change is difficult. How do enterprises transform their architecture with technologies like containers without losing the reliable components of their current solutions? In his session at @DevOpsSummit at 21st Cloud Expo, Tony Campbell, Director, Educational Services at CoreOS, will explore the challenges organizations are facing today as they move to containers and go over how Kubernetes applications can deploy with lega...
Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, will discuss some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he’ll go over some of the best practices for structured team migrat...