Mobility Information Series - SOAP XML JSON

Page created by Nathaniel Baldwin
 
CONTINUE READING
SOAP                                                 XML
  vs                    RapidValue
                              Enabling Mobility
                                                        vs
 REST                                                 JSON

Mobility Information Series
      Comparison between various
Web Services Data Transfer Frameworks for
      Mobile Enabling Applications

Author: Arun Chandran, Technical Architect, RapidValue Solutions
Contents

   Introduction                               3

   SOAP vs. REST                              3
            Performance                       4
            Maintenance                       4
            Security                          4
            Transactions                      4
            Messaging                         5
            Additional Parameters             5

   XML vs. JSON                               3
            Performance                       6
            Scenario                          6
                    Timing                    6
                    CPU/Memory                6

   Summary                                    7

   About RapidValue                           8

Mobility Information Series – Jan 2013   02
                                         02
Introduction
This document is a guide for developers and architects to select an appropriate framework to transfer
data between server and mobile devices. It explains the difference between two popular web services
architecture - SOAP & REST, and compares performance, maintenance, security, transactions,
messaging etc. between the two frameworks. The document also examines the pros and cons of two
commonly used data-interchange formats i.e. XML and JSON.

Ideal Approaches for Mobile Devices
There are two commonly used web services architecture - SOAP and REST. SOAP (Simple Object
Access Protocol) and REST (Representational State Transfer) provide mechanisms for requesting
information from endpoints (SOAP) or from resources (REST). SOAP has a more formal definition
mechanism called WSDL (Web Services Definition Language) and is slightly more complex to
implement than REST. REST uses the standard HTTP request and response mechanism, simplifies
implementation and provides a looser coupling of client and server.

REST has several advantages over SOAP. It is light weight. Therefore, data being passed will be lesser
over the network (since data is passed over a network to a mobile device). This makes a
considerable difference especially when Internet speed is low.

SOAP vs. REST
The table below provides a brief comparison between SOAP and REST.

  #       SOAP                                                    REST

  1       A XML-based message protocol                            An architectural style protocol

  2       Uses WSDL for communication between                     Uses XML or JSON to send and receive data
          consumer and provider

  3       Invokes services by calling RPC method                  Simply calls services via URL path

  4       Does not return human readable result                   Result is readable which is just plain XML or JSON

  5       Transfer is over HTTP. Also uses other                  Transfer is over HTTP only
          protocols such as SMTP, FTP, etc.

  6       JavaScript can call SOAP, but it is difficult to        Easy to call from JavaScript
          implement

  7       Performance is not great compared to REST               Performance is much better compared to SOAP -
                                                                  less CPU intensive, leaner code etc.

Mobility Information Series – Jan 2013                       03
                                                             02
This section describes differences between SOAP and REST in more detail:

Performance
–       REST is easier to use in JavaScript code as you can simply pass the data packet directly into a
        JavaScript array without any parsing, extracting and converting – lesser CPU intensive, since the
        CPU’s of mobile/tablets might be of lesser capacity compared to a laptop/desktop.

–       If the load of the server is considered, REST has slightly better performance since it accepts
        minimal overhead on top of HTTP. Usually SOAP brings with it a stack of different handlers and
        parsers. However, the performance difference by itself is not that large, but RESTful service is
        easier to scale up since there are no server side sessions.

–       If the performance of the network i.e. bandwidth is considered, REST has better performance,
        since it is only HTTP and no overhead. Therefore, if the service runs on top of HTTP, it cannot
        get much leaner than REST. Furthermore, if you encode your representations in JSON (as
        opposed to XML), you will save many more bytes.

–       REST reads can be cached, SOAP based reads cannot be cached.

In general, REST has better performance and scalability.

Maintenance

–       Building clients, developing APIs, and understanding the technical documentation is easier
        with REST than with SOAP.

Security

–       SOAP supports SSL and WS-Security which includes enterprise security features. It provides
        identity through intermediaries, not just point-to-point (SSL). It also provides standard
        implementation of data integrity and data privacy. It supports some security tools that typical
        internet services do not require; in fact they are mostly needed in few enterprise scenarios.

    Transactions

    –    REST is limited to HTTP which cannot provide two-phase commit across distributed
         transactional resources, whereas SOAP is capable.

Mobility Information Series – Jan 2013               04
                                                     02
Messaging
–       REST does not have a standard messaging system and expects clients to deal with
        communication failures by retrying. SOAP has successful/retry logic built-in and provides
        end-to-end reliability even through SOAP intermediaries.

Additional Parameters

–       Most mobile SDKs and jQuery support REST

–       REST supports synchronous and asynchronous process for mobiles

–       REST makes interface utilization easier in the client (device). Therefore, not only your server
        becomes leaner but the client too.

XML vs. JSON1
There are various formats available to transfer data between client and server. The most commonly
used ones are JSON and XML.

Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding
documents in a format which is both human-readable and machine-readable.

JavaScript Object Notation (JSON) is a text-based open standard designed for human-readable data
interchange. It is derived from the JavaScript scripting language for representing simple data structures
and associative arrays called objects. In spite of its relationship to JavaScript, it is language-
independent with parsers available for many languages. JSON format is often used for serializing and
transmitting structured data over a network connection. It is used primarily to transmit data between a
server and web application. It serves as an alternative to XML.

The table below provides a brief comparison between XML and JSON:

    #     XML                                                JSON

    1     XSD Validation                                     No Validation

    2     Includes namespaces                                No namespaces

    3     Requires parsing. xml doc is parsed through        Parsing is just an eval. Therefore it is fast.
          parameters like xpath etc.

    4     JavaScript work with strings. May require          In JavaScript, we can work with objects-run time
          additional parsing                                 evaluation of types

    5     Write JavaScript to parse the xml objects          A JavaScript object

    6     Heavy compared to JSON                             JSON is light weight compared to XML

Mobility Information Series – Jan 2013                  05
                                                        02
Performance
This section explains the difference between JSON and XML in the form of an experiment. This section
consists of test case results from a case study - research conduced by department of Computer
Science, Montana State University – Bozeman, USA. These test cases are designed and implemented
to compare transmission times and resource utilizations of JSON and XML.The results illustrate the
differences between JSON and XML encoding under varying transmission scenario.

Scenario 2: A time-consuming transmission of large number of objects.
Large numbers of objects are used in order to achieve accurate average measurements. The client
sends one million encoded objects to the server for both JSON and XML. The results are as follows:

Timing
  Parameters                                                          JSON                                  XML

  Number of Objects                                                   1 million                              1 million

  Total time to transfer million objects (ms)                         78257.9                                4546694.78

  Average time (ms)                                                   0.08                                   4.55

CPU/Memory
  Format                    Average % User CPU                       Average % System                        Average % Memory
                            Utilization                              CPU Utilization                         Utilization

  JSON                       86.13                                   13.08                                   27.37

  XML                       54.59                                   45.41                                    29.69

  Source:   1
                Wikipedia definitions
            2
                Comparison of JSON and XML Data Interchange Formats: A Case Study by Nurzhan Nurseitov, Michael Paulson, Randall Reynolds,
                Clemente Izurieta, Montana State University

Mobility Information Series – Jan 2013                                   06
                                                                         02
Summary
Based on our experience and usage of various web service frameworks, our recommendations are as
follows:

–       If the application requires transferring highly secure data, then the best option will be to use
        SOAP.

–       If high security is not a concern, then REST would be the ideal choice as REST services is easier
        to develop, maintain and performance of the application will be better - consumes lesser CPU
        memory, works well at lower bandwidth even during high transactions.

–       JSON is recommended over XML for data transmission over the Internet, especially when
        interactions with mobile devices are involved since it is light weight data-interchange format.

If you have any questions or need further information, please do write to us.

Mobility Information Series – Jan 2013               07
                                                     02
About RapidValue
RapidValue is a leading provider of end-to-end mobility solutions to enterprises worldwide. Armed with
a large team of experts in mobility consulting and application development, along with experience
delivering global mobility projects, we offer a range of mobility services across industry verticals.
RapidValue delivers its services to the world’s top brands and Fortune 1000 companies, and has offices
in the United States and India.

                  www.rapidvaluesolutions.com           www.rapidvaluesolutions.com/blog

                         +1-877-643-1850               contactus@rapidvaluesolutions.com

Mobility Information Series – Jan 2013
You can also read