Understanding the Difference Between Web Services and Service Layer

web services

My understanding of a webservice and service layer is as follows –

Service Layer: An abstraction layer which exposes a set of common operations which can be used by multiple consumers. For instance , I have a database containing customer data. Multiple applications may want to add / update / delete data in this data store. Each application will have logic to add / update / delete data in data store – hence duplication of logic. Instead, I would provide a service layer which exposes methods to add / update / delete customer information. So the logic isn't duplicated any longer and the applications have to just use my service layer in order to perform these activities. The specific domain where the service layer operates here is on customer information.

Webservices: Any machine to machine data transfer over the web can be performed using webservices. The implementation of webservice can be SOAP, REST, vanilla RMI, etc… and the data can be serialized as XML, JSON, binary, etc… Assuming I expose a SOAP based webservice for the use case listed in my example above, I could provide a SOAP or REST based interface to add / delete / update customer information. The domain here is customer as well.

Based on my understanding, I feel that webservices are a subset of the service layer. The implementation for the example use case can be provided in the form a java .jar file or DLL which provides relevant APIs to perform the activity. All of the required applications will have to download the appropriate .jar or DLL to perform actions on customer data. Whereas webservice is specifically for machine-machine communication over web.

Is my understanding correct?

Best Answer

A service layer is a layer in an application that hides away specific implementation details for a system and provides a uniform and consistent interface to the operations in that system.

A webservice is a communication pattern between devices.

The service layer defines a boundary for your system where external systems can interact with it. If you do this purely in code by providing a DLL, other systems interface with your service layer directly. Alternatively, you can provide a webservice on top of your DLL in which case other systems interface with the webservice, which interfaces with the DLL.

Compare this to a shop that has both a physical counter and an online store. Your salespeople are the 'service layer': they 'hide away' the implementation details that deal with registering a sale in the Point of Sale register, they handle the procedures that deal with performing additional purchases for a product that is out of stock, they put the cash from the customer in the right place and so on.

In the online store, your website acts as a 'web service': a customer no longer has to talk to a salesperson but instead places an order through the website. That order gets passed to a salesperson, who again performs the same things as outlined. The communication pattern is different, but the customer only cares about getting the product and knows that he has a variety of ways to do that.

Related Topic