Welcome!

Microservices Expo Authors: Yeshim Deniz, Pat Romanski, Todd Matters, Mark Leake, Stefana Muller

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
Cloud Expo, Inc. has announced today that Andi Mann and Aruna Ravichandran have been named Co-Chairs of @DevOpsSummit at Cloud Expo Silicon Valley which will take place Oct. 31-Nov. 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. "DevOps is at the intersection of technology and business-optimizing tools, organizations and processes to bring measurable improvements in productivity and profitability," said Aruna Ravichandran, vice president, DevOps product and solutions marketing...
"When we talk about cloud without compromise what we're talking about is that when people think about 'I need the flexibility of the cloud' - it's the ability to create applications and run them in a cloud environment that's far more flexible,” explained Matthew Finnie, CTO of Interoute, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
For most organizations, the move to hybrid cloud is now a question of when, not if. Fully 82% of enterprises plan to have a hybrid cloud strategy this year, according to Infoholic Research. The worldwide hybrid cloud computing market is expected to grow about 34% annually over the next five years, reaching $241.13 billion by 2022. Companies are embracing hybrid cloud because of the many advantages it offers compared to relying on a single provider for all of their cloud needs. Hybrid offers bala...
A common misconception about the cloud is that one size fits all. Companies expecting to run all of their operations using one cloud solution or service must realize that doing so is akin to forcing the totality of their business functionality into a straightjacket. Unlocking the full potential of the cloud means embracing the multi-cloud future where businesses use their own cloud, and/or clouds from different vendors, to support separate functions or product groups. There is no single cloud so...
Containers, microservices and DevOps are all the rage lately. You can read about how great they are and how they’ll change your life and the industry everywhere. So naturally when we started a new company and were deciding how to architect our app, we went with microservices, containers and DevOps. About now you’re expecting a story of how everything went so smoothly, we’re now pushing out code ten times a day, but the reality is quite different.
"We are a monitoring company. We work with Salesforce, BBC, and quite a few other big logos. We basically provide monitoring for them, structure for their cloud services and we fit into the DevOps world" explained David Gildeh, Co-founder and CEO of Outlyer, in this SYS-CON.tv interview at DevOps Summit at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
21st International Cloud Expo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud strategy. Me...
If you cannot explicitly articulate how investing in a new technology, changing the approach or re-engineering the business process will help you achieve your customer-centric vision of the future in direct and measurable ways, you probably shouldn’t be doing it. At Intellyx, we spend a lot of time talking to technology vendors. In our conversations, we explore emerging new technologies that are either disrupting the way enterprise organizations work or that help enable those organizations to ...
In 2014, Amazon announced a new form of compute called Lambda. We didn't know it at the time, but this represented a fundamental shift in what we expect from cloud computing. Now, all of the major cloud computing vendors want to take part in this disruptive technology. In his session at 20th Cloud Expo, Doug Vanderweide, an instructor at Linux Academy, discussed why major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform are all trying to sidestep VMs and containers wit...
The taxi industry never saw Uber coming. Startups are a threat to incumbents like never before, and a major enabler for startups is that they are instantly “cloud ready.” If innovation moves at the pace of IT, then your company is in trouble. Why? Because your data center will not keep up with frenetic pace AWS, Microsoft and Google are rolling out new capabilities. In his session at 20th Cloud Expo, Don Browning, VP of Cloud Architecture at Turner, posited that disruption is inevitable for comp...
For organizations that have amassed large sums of software complexity, taking a microservices approach is the first step toward DevOps and continuous improvement / development. Integrating system-level analysis with microservices makes it easier to change and add functionality to applications at any time without the increase of risk. Before you start big transformation projects or a cloud migration, make sure these changes won’t take down your entire organization.
There's a lot to gain from cloud computing, but success requires a thoughtful and enterprise focused approach. Cloud computing decouples data and information from the infrastructure on which it lies. A process that is a LOT more involved than dragging some folders from your desktop to a shared drive. Cloud computing as a mission transformation activity, not a technological one. As an organization moves from local information hosting to the cloud, one of the most important challenges is addressi...
What's the role of an IT self-service portal when you get to continuous delivery and Infrastructure as Code? This general session showed how to create the continuous delivery culture and eight accelerators for leading the change. Don Demcsak is a DevOps and Cloud Native Modernization Principal for Dell EMC based out of New Jersey. He is a former, long time, Microsoft Most Valuable Professional, specializing in building and architecting Application Delivery Pipelines for hybrid legacy, and cloud ...
Companies have always been concerned that traditional enterprise software is slow and complex to install, often disrupting critical and time-sensitive operations during roll-out. With the growing need to integrate new digital technologies into the enterprise to transform business processes, this concern has become even more pressing. A 2016 Panorama Consulting Solutions study revealed that enterprise resource planning (ERP) projects took an average of 21 months to install, with 57 percent of t...
Microservices are increasingly used in the development world as developers work to create larger, more complex applications that are better developed and managed as a combination of smaller services that work cohesively together for larger, application-wide functionality. Tools such as Service Fabric are rising to meet the need to think about and build apps using a piece-by-piece methodology that is, frankly, less mind-boggling than considering the whole of the application at once. Today, we'll ...
In his session at Cloud Expo, Alan Winters, an entertainment executive/TV producer turned serial entrepreneur, presented a success story of an entrepreneur who has both suffered through and benefited from offshore development across multiple businesses: The smart choice, or how to select the right offshore development partner Warning signs, or how to minimize chances of making the wrong choice Collaboration, or how to establish the most effective work processes Budget control, or how to ma...
Hybrid IT is today’s reality, and while its implementation may seem daunting at times, more and more organizations are migrating to the cloud. In fact, according to SolarWinds 2017 IT Trends Index: Portrait of a Hybrid IT Organization 95 percent of organizations have migrated crucial applications to the cloud in the past year. As such, it’s in every IT professional’s best interest to know what to expect.
Both SaaS vendors and SaaS buyers are going “all-in” to hyperscale IaaS platforms such as AWS, which is disrupting the SaaS value proposition. Why should the enterprise SaaS consumer pay for the SaaS service if their data is resident in adjacent AWS S3 buckets? If both SaaS sellers and buyers are using the same cloud tools, automation and pay-per-transaction model offered by IaaS platforms, then why not host the “shrink-wrapped” software in the customers’ cloud? Further, serverless computing, cl...
In the decade following his article, cloud computing further cemented Carr’s perspective. Compute, storage, and network resources have become simple utilities, available at the proverbial turn of the faucet. The value they provide is immense, but the cloud playing field is amazingly level. Carr’s quote above presaged the cloud to a T. Today, however, we’re in the digital era. Mark Andreesen’s ‘software is eating the world’ prognostication is coming to pass, as enterprises realize they must be...
Colocation is a central pillar of modern enterprise infrastructure planning because it provides greater control, insight, and performance than managed platforms. In spite of the inexorable rise of the cloud, most businesses with extensive IT hardware requirements choose to host their infrastructure in colocation data centers. According to a recent IDC survey, more than half of the businesses questioned use colocation services, and the number is even higher among established businesses and busin...