Development of Web Services for Android Applications

Post on 14-Jan-2017

238 views 1 download

Transcript of Development of Web Services for Android Applications

Development of Web Services for Android Applications

Md Ashraful Haque

2Introduction

In present days, the ability to seamlessly exchange information between internal business units, customers, and partners is vital for success

Yet most organizations employ a variety of disparate applications that store and exchange data in dissimilar ways and therefore cannot "talk" to one another productively

Web services have evolved as a practical, cost-effective solution for uniting information distributed between critical applications over operating system, and language barriers that were previously impossible

3

In last few years the use of smartphones and tablets has been increased enormously, changing the scenario of mobile phone usage

The applications associated with this smartphones and tablets are the most attractive tools which provides a touch and click interface to the users

According to Nielsen Media Research • In 2014, the mobile users spent 89% of their time on media through the mobile

Application

Contd…

4 Now-a-days Android operating system has become a predominant platform in the

market of application development. (Shanmugapriya et al., 2011)

Several companies as part of OHA (Open Handset Alliances) developing millions of Android applications

e-learning to m-learning, e-commerce to m-commerce

In this shifting from web-based application to mobile application, web services act as the intermediate interface

Contd…

5Web service overview Web service is a standardized technology that

• Exposes information, functionalities and business logic of a existing web-server/web page application over the Internet

• Allows other system/application to access these information, functionalities and business logic by calling the web methods

• provides program-to-program interface between the systems/application

• Uses some open standards or protocols like SOAP, WSDL and UDDI

6

o Device A request some data from other system B over the network

o System B exposes the data using a web service through the network

o System A gets the response data as a result

Web services communicate between different systems/applications

Contd…

WEB SERVICE

7 Web services are independent of programming language and platform (Kao,

2001)

Contd…

8Architecture of web services Web services Architecture is defined by SOA (Service Oriented

Architecture)• SOA concept refers to a architecture based on some distinct services• Interaction between these services exist

According to SOA there are three components in a web services-• Service roles/actors• Service operations• Standards/Protocols

9

SERVICE REQUESTOR

SERVICE PROVIDER

SERVICE REGISTRY

XML

XML

SERVICE RESPONSE

SERVICE REQUEST

BIND/INTERACT

PUBLISH(WSDL)

FIND/LOCATE(WSDL+UDDI)

SOAP

SOAP

The service actor are-o Service provider

o Service Requestor

o Service Registry

The operations performed o Publish

o Find/Locate

o Bind/Interact

Contd…

10 Standards/protocols of web service

SOAP (Simple Object Access Protocol)

• It is XML-based messaging protocol, where XML (eXtensible Markup Language) provides tags to each element of the message

• The basic communication between the systems are served by SOAP Request and SOAP Response

• Also known as Communication Protocol

Contd…

11Contd…

• Framework of SOAP-

o Has components like envelop, header, body

o The message elements are encapsulated in the SOAP envelop

12Contd… WSDL(Web Services Description Language)-

• The service description is specified in the WSDL file

• XML-document format

• Provides location (URL) of the service and description of the service to a client application

13Contd… UDDI (Universal Description, Discovery and Integration)

• XML-based standard for publishing, finding and registering web services

• It acts as a centralised registry that enables the clients to locate the web services.

• Closely resembles online “Phone Directory” (Dustdar, et al., 2005)

• Provide two basic informationo Service description along with the way to encode ito Query and update APIs of the registry

14Introducing the Android Application Android Platform

• Open source software stack for mobile application development

• Google initiated android project with Open Handset Alliance including 30 companies (Knutsen, 2009)

• Linux based kernel and runs its application on Dalvik Virtual Machine

• Several version has released till today, the latest version released is Lollipop (Android 5.0) and Android M is the upcoming release.

15Contd… Advantages of Android Platform

• Open source software

• Android integration in any device

• Devices can be easily customizable

• No external review required

16Contd…

Architecture of android platform

o Four layers and five sections

17Importance of web services in android Applications

Using and implementing functionalities of existing web-based systems/applications

Access data from remote database server easily

Client users can access the web service in an emergency situation if health related web services are available

User get information on touch and click using a web service through the application

18Developing a web service in java Programming language

Creating a web service that will access a remote database server Creating a web service class and web methods

Creating Database Source Name (DSN)

Accessing database in java

Deploy and Testing the web service

19Contd… Creating web service class and web methods

• A web service consists of a set of web service class and web methods

• Web service classes encapsulate all the web methods used in the service

• Web methods are the actual implementation of exposing the functionality of a system over the network

20Contd..

o @WebService (serviceName = “test”)

o @WebMethod(operationName=“loginid”)

o @WebParam (name =“username”)

21Contd… Creating Database Source Name (DSN)

• Database source name provides connectivity to a database through an ODBC driver

• DSN contains database name, database

driver, directory and other information

• Once a DSN is created, one can use the

DSN in an web service to invoke

information from the database

22Contd… Accessing the database in Java

• Java provides a set of classes that connects the database by loading the ODBC driver

23Contd… Deploying and Testing web service

• To make the web service available to any client application, the service have to be deployed

• The web service has been deployed to the Glassfish server so that the service can be available over the Internet

• The web service can be tested by tester in the browser

24Contd…

Web method is tested by click on the loginid button

Service description file

25Contd… The WSDL file

o URL to access the web service

o Method or the operation

o Data types used in method parameter and return types

26Contd…

Parameter Provided

Method returns a value

27Contd…

o The SOAP request and SOAP response.

28Consuming the web service in Android applications

An android application can be developed as client application for consuming the web service

Android application creates a request to the web service, the web service responses to the application with desired result

29Contd…

Key points of Android Application for consuming a web service are-

Creating layout files in XML

Creating activity class files in JAVA

Accessing the web service inside the application

Internet Permission in the manifest file

30Contd... Creating Layout file in XML-

• Framework of each activity of an application is defined in the layout file

• Just a XML file with tags

• It can define different elements such aso Form widgets- Buttons, Progress Bar, TextView etco Text fields- EditText, Password, Date, E-mail etco Layout- Linear, Relative etc

31Contd…Referring a linear layout

Referring a textview within the application

Referring a text editor in the application

Referring a button to be clicked

32Contd… Creating the activity class file in java

• most important files in the application written in java programming language

• ultimately converted in Dalvik executable file and runs the application

• Inherits the base classes of android like Activity Class, ActionBarActivity Class etc

• Implements and overrides the necessary methods such as onCreate(), onClick() etc

33Contd…• performing the following functionality-

o Defines the XML-layout elements and provide reference of the XML elements into java

o sets the content view of the application as per the XML-layout file

34Contd…o Sets tasks in application after the button is clicked

35Contd… Accessing the web service inside the application

• Most important part of the application that actually calls the web method• Add a third party library KSOAP2 (http://ksoap2.sourceforge.net) to the library

of Android project that is optimized for Android

36Contd…

• Firstly defines the namespace of the web service, name of the web method, SOAP-Action and the URL of the web service description

37Contd…

• SOAP request is fired based upon the specified web method of the web service and properties are added as per the requirement

• SOAP envelop is created and version of the SOAP is declared

38Contd…• Passing the request to the envelop

• Connecting to the web service using the URL and invoking the web method with request

• The response of the request is stored as String

39Contd…

Internet permission in the manifest file

• the application needs a permission for accessing the Internet

40Current Technology RESTful-based web service

• has gained wide acceptance across worldwide in last few years

• It is being used as a simpler alternative to SOAP and WSDL-based web services (Zur et. al, 2005)

• REST stands for Representational State Transfer, defines a set of architectural principles for developing web services

• It typically communicate over HTTP with the same HTTP principle CRUD (create, Read, update, Delete)

41Conclusions-

Companies/organisations are developing web services to integrate the existing functionalities and resources of multiple systems/applications

e-commerce companies like Flikart, Amazon, Snapdeal, Myntra, Paytm expanding themselves through mobile application version

Web services can be developed for the agricultural information system so that any client application can access those facilities easily

Further studies on RESTful web services for Android application can be done