1. Overview
1.1 What is a web service?
1.2 What is a web service?(cont.)
2. Working with SOAP services
2.1 What is SOAP?
2.2 What is SOAP? (cont.)
2.3 Why is SOAP Needed?
2.4 SOAP Building Blocks
2.5 SOAP Building Blocks (cont.)
3. Working with XML
3.1 What is XML?
3.2 What is XML Parser?
3.3 The main types of parsers?
3.4 What is SAX parser?
3.5 What is SAX parser? (cont.)
3.6 What is DOM parser?
3.7 What is DOM parser? (cont.)
3.8 What is Pull parser?
3.9 What is Pull parser? (cont.)
4. Using KSoap2 Library
4.1 What is KSoap2?
4.2 Why is KSoap2 Needed?
5. Working with Restful web services
6. Working with JSON
6.1 What is JSON?
6.2 JSON’s basic types
4. Android Programming
Overview
What is a web service?
A Web service is a method of communication between two
electronic devices over the World Wide Web.
The most important factor to the success and popularity of web
services is the fact that its backbone is XML.
4
8. Android Programming
Working with SOAP services
What is SOAP?
SOAP stands for Simple Object Access Protocol
SOAP is a communication protocol
SOAP is for communication between applications
SOAP is a format for sending messages
SOAP communicates via Internet
8
9. Android Programming
Working with SOAP services
What is SOAP? (cont.)
SOAP is platform independent
SOAP is language independent
SOAP is based on XML
SOAP is simple and extensible
SOAP is a W3C recommendation
9
10. Android Programming
Working with SOAP services
Why is SOAP Needed?
It is important for application development to allow Internet
communication between programs.
HTTP is supported by all Internet browsers and servers.
SOAP provides a way to communicate between applications
running on different operating systems, with different technologies
and programming languages.
10
12. Android Programming
Working with SOAP services
SOAP Building Blocks (cont.)
An Envelope element that identifies the XML document as a
SOAP message.
A Header element that contains header information.
A Body element that contains call and response information.
12
16. Android Programming
Working with XML
What is XML?
XML stands for EXtensible Markup Language
XML is a markup language much like HTML
XML was designed to carry data, not to display data
XML tags are not predefined. You must define your own tags
XML is designed to be self-descriptive
XML is a W3C Recommendation
16
17. Android Programming
Working with XML
What is XML Parser?
A parser is a piece of program that takes a physical representation
of some data and converts it into an in-memory form for the
program as a whole to use.
Parsers are used everywhere in software.
An XML Parser is a parser that is designed to read XML and
create a way for programs to use XML.
17
18. Android Programming
Working with XML
The main types of parsers?
The main types of parsers are known by some names:
• SAX
• DOM
• Pull
18
19. Android Programming
Working with XML
What is SAX parser?
A SAX (Simple API for XML) parser does not create any internal
structure. Instead, it takes the occurrences of components of an
input document as events, and tells the client what it reads as it
reads through the input document.
A SAX parser serves the client application always only with
pieces of the document at any given time.
19
20. Android Programming
Working with XML
What is SAX parser? (cont.)
A SAX parser, however, is much more space efficient in case of a
big input document (because it creates no internal structure).
What’s more, it runs faster and is easier to learn than DOM
parser because its API is really simple.
But from the functionality point of view, it provides a fewer
functions, which means that the users themselves have to take
care of more, such as creating their own data structures.
20
23. Android Programming
Working with XML
What is DOM parser?
A DOM (Document Object Model) parser creates a tree structure
in memory from an input document and then waits for requests
from client.
A DOM parser always serves the client application with the entire
document no matter how much is actually needed by the client.
23
24. Android Programming
Working with XML
What is DOM parser? (cont.)
A DOM parser is rich in functionality.
It creates a DOM tree in memory and allows you to access any
part of the document repeatedly and allows you to modify the
DOM tree.
But it is space inefficient when the document is huge, and it takes
a little bit longer to learn how to work with it.
24
26. Android Programming
Working with XML
What is Pull parser?
SAX is a push parser, since it pushes events out to the calling
application.
Pull parsers, on the other hand, sit and wait for the application to
come calling. They ask for the next available event, and the
application basically loops until it runs out of XML.
26
27. Android Programming
Working with XML
What is Pull parser? (cont.)
Pull parsers are useful in streaming applications, which are areas
where either the data is too large to fit in memory.
It is designed to be used with large data sources, and unlike SAX
which returns every event, the pull parser can choose to skip
events that it is not interested in.
27
29. Android Programming
Working with XML
What is Pull parser? (cont.)
The above example will generate the following output:
• Start document
• Start tag contact
• Text Nguyen Van A
• End tag contact
• End document
29
32. Android Programming
Using KSoap2 Library
What is KSoap2?
KSOAP is a SOAP web service client library for constrained
Java environments such as Applets or J2ME applications (CLDC /
CDC / MIDP).
The ksoap2-android project provides a lightweight and efficient
SOAP client library for the Android platform.
http://code.google.com/p/ksoap2-android/
32