[Android] Web services

1,542 views

Published on

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

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,542
On SlideShare
0
From Embeds
0
Number of Embeds
60
Actions
Shares
0
Downloads
0
Comments
0
Likes
4
Embeds 0
No embeds

No notes for slide

[Android] Web services

  1. 1. Android Programming Lesson 10Web services NGUYEN The Linh
  2. 2. Android ProgrammingContents 1 Overview 2 Working with SOAP services 3 Working with XML 4 Using KSoap2 Library 2
  3. 3. Android ProgrammingWeb services Overview 3
  4. 4. Android ProgrammingOverview 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
  5. 5. Android ProgrammingOverview What is a web service?(cont.) 5
  6. 6. Android ProgrammingOverview What is a web service?(cont.) Request -> POST XML Web services Response XML 6
  7. 7. Android ProgrammingWeb services Working with SOAP services 7
  8. 8. Android ProgrammingWorking 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. 9. Android ProgrammingWorking 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. 10. Android ProgrammingWorking 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
  11. 11. Android ProgrammingWorking with SOAP services SOAP Building Blocks 11
  12. 12. Android ProgrammingWorking 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
  13. 13. Android ProgrammingWorking with SOAP services 13
  14. 14. Android ProgrammingWorking with SOAP services 14
  15. 15. Android ProgrammingWeb services Working with XML 15
  16. 16. Android ProgrammingWorking 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. 17. Android ProgrammingWorking 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. 18. Android ProgrammingWorking with XML The main types of parsers?  The main types of parsers are known by some names: • SAX • DOM • Pull 18
  19. 19. Android ProgrammingWorking 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. 20. Android ProgrammingWorking 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
  21. 21. Android ProgrammingWorking with XML 21
  22. 22. Android ProgrammingWorking with XML 22
  23. 23. Android ProgrammingWorking 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. 24. Android ProgrammingWorking 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
  25. 25. Android ProgrammingWorking with XML 25
  26. 26. Android ProgrammingWorking 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. 27. Android ProgrammingWorking 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
  28. 28. Android ProgrammingWorking with XML 28
  29. 29. Android ProgrammingWorking 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
  30. 30. Android ProgrammingWorking with XML Example 10.1  GetLove App  http://nikmesoft.com/apis/J4FServices/ index.php 30
  31. 31. Android ProgrammingWeb services Using KSoap2 Library 31
  32. 32. Android ProgrammingUsing 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
  33. 33. Android ProgrammingUsing KSoap2 Library Why is KSoap2 Needed? Send Request (XML) Get Response (XML) Parsing XML 33
  34. 34. Android ProgrammingUsing KSoap2 Library Why is KSoap2 Needed? Send Request (XML) Get Response (XML) Parsing XML 34
  35. 35. Android ProgrammingUsing KSoap2 Library Why is KSoap2 Needed? Parsing Send XML Request KSOAP2 (XML) Get Response All In One (XML) 35
  36. 36. Android ProgrammingUsing KSoap2 Library Example 10.2  Using KSoap2 36
  37. 37. Android Programming

×