Lets start with Application vs WebsiteNow-a-days, in the world of mobile applications and web application, it is imperative that the maintenance and development efforts are kept to minimum. If a company is running a website as well as mobile application (probably supporting multiple platforms, especially iOS and Android), then it is first step to separate the UI interaction layer from the Database interaction layer.
Now, there could be companies running both Websites and Applications or could be companies willing to try only application approach, like Flipkart's Myntra app, Ola or Uber app, etc.
For these mobile apps, to interact with databases, API (Application Program Interface) has to be build. This is where webservices come into picture. Webservice based API are build and are used by mobile applications irrespective of the platform for which an application is built on. Thus, a webservice will cater for iOS, Android as well as Windows phone applications. The webservice can be build in any programming language without affecting the platform using the webservice.
Understanding Web-service - an introduction
- Web-service is a system that enables different applications to communicate with some API.
- Web-service helps to communicate with different systems over network by following some standards or protocols for exchanging information.
- There are two components involved, one providing the service is web service provider and the one utilizing it is web service consumer or client.
- Thus, a service is a software component provided through a network-accessible endpoint. The service consumer and provider use messages to exchange invocation request and response information.
- For example, java application can interact with Java, .Net and PHP applications. So web service is a language independent way of communication.
SOAP Web Service
- Simple Object Access Protocol (SOAP) is an XML based specification/ protocol for the web service message format and communication over network.
- It helps to describe the transport method and message format in a web service, which is platform and language independent.
- SOAP defines its own security known as WS Security.
Features of SOAP based web-service
Web Services Description Language (WSDL)
- WSDL is a standard provided by W3C consortium.
- It is used to describe a web service in an XML file.
- It covers all the aspects of a web service like,
- message format,
- communication protocol,
- A WSDL xml file for a web service is generally expected to be published publicly; so that we can understand the nature of service and consume it accordingly.
- Types is an important element in WSDL.
- It is used to describe the message attributes and respective types.
- XSD is the preferred format to describe the types. Type definition can be given in a separate XSD file and imported in WSDL.
Universal Description, Discovery and Integration (UDDI)
- UDDI is a directory service.
- Web services can register with a UDDI and make themselves available through it for discovery.
Stub and Skeleton
- Stub and skeleton are counterparts in a web service setup.
- Skeleton belongs to service provider side and stub belongs to receiver or client side.
- At lower level, from client side the business objects communicate with stub objects; then stubs take the responsibility, form the message and invoke the web service.
- Once the service is invoked, skeleton is the parallel object for stub; it receives the request message, understands it and passes on the information to service side business objects.
- An endpoint is a particular network location with associated protocol
- It includes message format mapping using which we can access the instance of web service.
- Endpoint is described in WSDL file. In short, it's a handle to access the web service.
- It helps to associate an interface with a protocol and message format.
- It is used in endpoint definition.
- It is described in WSDL.
- Operation is a logical grouping of meaningful actions comprises of a request and response.
- Group of operations forms a web service.
RESTful Web Service
- REpresentational State Transfer (REST) is a stateless client-server architecture
- Web services are viewed as resources and can be identified by their URIs.
- Web service clients that want to use these resources access via globally defined set of remote methods that describe the action to be performed on the resource. Here clients and servers exchange representations of resources by using a standardized interface and protocol. REST isn't protocol specific, but when people talk about REST they usually mean REST over HTTP.
The response from server is considered as the representation of the resources. This representation can be generated from one resource or more number of resources. REST allows that resources have different representations, e.g.xml, json etc. The rest client can ask for specific representation via the HTTP protocol.
RESTful web services use standard HTTP protocol methods for the operations they perform such as,
- GET: It defines a reading access of the resource.
- POST: It updates an existing resource or creates a new resource.
- PUT: It creates a new resource.
- DELETE: It removes the resources.
Features of RESTful web services
Resource identification through URI
Resources are identified by their URIs (typically links on internet). So, a client can directly access a RESTful Web Services using the URIs of the resources (same as you put a website address in the browser's address bar and get some representation as response).
Resources are manipulated using a fixed set of CRUD (create, read, update, delete) operations viz. PUT, GET, POST, and DELETE.
Each request from client to server must contain all the information necessary to understand the request, and cannot take advantage of any stored context on the server.
Cache is used to improve network efficiency responses and must be capable of being labeled as cacheable or non-cacheable
Intermediaries, such as proxy servers, cache servers, gateways, etc, can be inserted between clients and resources to support performance, security, etc.
Resources are decoupled from their representation so that their content can be accessed in a variety of formats, such as HTML, XML, plain text, PDF, JPEG, JSON, and others.
Ways to implement a web service
Bottom Up Approach
- In this approach we first define the logic of a web service and then using that we can build the interface.
- Service code is written first and then the WSDL is created using the service code.
- There are tools available to generate the WSDL file automatically.
Top Down Approach
- Top down is the reverse of bottom up approach.
- In this approach WSDL is created first. The complete service definition, message format, transport protocol, security and everything is described in WSDL.
- Service logic is written after the WSDL. Using that WSDL the skeleton code is generated automatically.
Hope this article has given you a kick-start on understanding of web-services and using them.