Monday, November 28, 2011

Webservices in android


Web services provide a standard means of interoperating between different software applications, running on a variety of platforms and/or frameworks
A Web service is a software system designed to support interoperable machine-to-machine interaction over a network. It has an interface described in a machine-processable format (specifically WSDL). Other systems interact with the Web service in a manner prescribed by its description using SOAP messages, typically conveyed using HTTP with an XML serialization in conjunction with other Web-related standards
The basic Web services platform is XML + HTTP.

What are Web Services?
  • Web services are small units of code
  • Web services are designed to handle a limited set of tasks
  • Web services use XML based communicating protocols
  • Web services are independent of operating systems
  • Web services are independent of programming languages
  • Web services connect people, systems and devices
Benefits of Web Services
  • Easier to communicate between applications
  • Easier to reuse existing services
  • Easier to distribute information to more consumers
  • Rapid development

Web Services Standards (XML-based)
1– SOAP (Simple Object Access Protocol)
SOAP is an XML-based protocol to let applications exchange information over HTTP.
Or more simple: SOAP is a protocol for accessing a Web Service.
SOAP provides a way to communicate between applications running on different operating systems, with different technologies and programming languages.
  • SOAP stands for Simple Object Access Protocol
  • SOAP is a communication protocol
  • SOAP is a format for sending messages
  • SOAP is designed to communicate via Internet
  • SOAP is platform independent
  • SOAP is language independent
  • SOAP is based on XML
  • SOAP is simple and extensible
  • SOAP allows you to get around firewalls
  • SOAP is a W3C standard
2– WSDL (Web Service Description Language)
WSDL is an XML-based language for locating and describing Web services.
  • WSDL stands for Web Services Description Language
  • WSDL is based on XML
  • WSDL is used to describe Web services
  • WSDL is used to locate Web services
  • WSDL is a W3C standard

3– UDDI (Universal Description, Discovery, Integration)
UDDI is a directory service where companies can register and search for Web services.
Universal Description, Discovery, and Integration (UDDI) is a protocol for describing available Web services components. This standard allows businesses to register with an Internet directory that will help them advertise their services, so companies can find one another and conduct transactions over the Web. This registration and lookup task is done using XML and HTTP(S)-based mechanisms.
  • UDDI stands for Universal Description, Discovery and Integration
  • UDDI is a directory for storing information about web services
  • UDDI is a directory of web service interfaces described by WSDL
  • UDDI communicates via SOAP
  • UDDI is built into the Microsoft .NET platform

Xml Parsing
XML stands for eXtensible Markup Language.
XML is designed to transport and store data.
Types of Parser:
1.       Sax    —   Simple Api for Xml
2.       Dom   ----    Document Object Model
3.       XmlPull 

Diff B/W Sax and Dom
Both SAX and DOM are used to parse the XML document. Both has advantages and disadvantages and can be used in our programming depending on the situation.
Parses node by node
Stores the entire XML document into memory before processing
Doesn’t store the XML in memory
Occupies more memory
We cant insert or delete a node
We can insert or delete nodes
Top to bottom traversing
Traverse in any direction.
SAX is an event based parser
DOM is a tree model parser
SAX is a Simple API for XML
Document Object Model (DOM) API
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import javax.xml.parsers.*;
import org.w3c.dom.*;
doesn’t preserve comments
preserves comments
SAX generally runs a little faster than DOM
SAX generally runs a little faster than DOM
If we need to find a node and doesn’t need to insert or delete we can go with SAX itself otherwise DOM provided we have more memory.

Diff B/W Sax and Xml Pull Parser
·         These are both ways to parse large XML files without using a lot of memory resources. They don't let you modify or generate XML; these "XML readers" let you read through a large XML file efficiently, using a small amount of memory.
·         SAX uses callbacks and pull parsers don't
·         SAX model: after you set up callbacks, the SAX component pushes document events to you
·         pull parser model: you pull data from the document using the pull parser component
·         The pull parser model is more flexible and dramatically easier to work with. You don't need to do any setup and there is much less you need to know to use it.

Graphical  Representation about Parser Performance

Source Code
you can find source code in followling link

Click Here to Download