UNIT –2
Web Services Type System
Web services provide common platform that allow different applications, have the ability to communicate ,with each other by various programming languages.
Therefore web service can be defined in the following ways:
- Client-server application or application component for communication.
- Communication between two devices over network.
- Software system for interoperable machine to machine communication
- Collection of standards or protocols for exchanging information between two devices.
Here we see that java,.net or PHP applications communicate with other applications through web service. Therefore web service is a language for independent way of communication.
Types of Web Services:
There are mainly two types of web services
- SOAP
- Restful
SOAP(Simple Object Access Protocol)
- XML-based protocol for accessing web services.
- W3C recommendation for communication between two applications
- It is platform independent and language independent.
- Provides interaction with other programming language applications.
Advantages:
SOAP defines its own security known as WS Security.
SOAP web services can be written in any programming language and executed in any platform.
Disadvantages:
- SOAP is slow, as well as consumes more bandwidth and resource, since it defines many standards, which has to be followed while developing SOAP applications.
- SOAP uses WSDL and does not have any other mechanism to discover the service.
RESTFUL
- REST stands for Representational State Transfer.
- Rest is an architectural style not a protocol.
Advantages :
Fast ,consumes less bandwidth and resource.
Written in any programming language and executed in any platform
Use SOAP web services as implementation.
Permits different data format such as Plain Text, HTML, XML and JSON.
S.No | SOAP | REST | ||
1 | SOAP is a protocol. | REST is an architectural style. | ||
3 | SOAP can't use REST because it is a protocol. | REST can use SOAP web services because it is a concept and can use any protocol like HTTP, SOAP. | ||
4 | SOAP uses services interfaces to expose the business logic. | REST uses URI to expose business logic. | ||
5 | SOAP defines standards to be strictly followed. | REST does not define too much standards like SOAP. | ||
7 | SOAP requires more bandwidth and resource than REST. | REST requires less bandwidth and resource than SOAP. | ||
8 | SOAP defines its own security. | RESTful web services inherit security measures from the underlying transport. | ||
9 | SOAP permits XML data format only. |
|
Web Services use simple parameters, such as strings and integers. But most systems will need to pass complex types such as arrays, classes, and data structures. Let us see how such complex types can be mapped between Java and SOAP/WSDL and create an order service that uses these types.
Mapping Between Java and SOAP/WSDL Types
For simple types, SOAP and WSDL use the representations defined in "XML Schema Part 2:
Datatypes" that is part of the W3C XML Schema standard.
There is a straight mapping for all Java primitive types except for char.
There is also a straight mapping for the Java String class.
But in case of arrays and complex Java types, such as your own classes, more effort must be put into the representation of these mappings. Consider what is done by RMI when you pass Java objects between a client and server:
- RMI uses the Java serialization mechanism to convert the contents of the object into a byte stream that can be sent across the network.
- Both client and server must have a definition for the type being passed (or must be able to get hold of one).
- The remote interface definition uses standard Java syntax to indicate where objects are used as parameters or return values.
When using complex Java types as part of a Web Service, , there is the added complication that you must do this in a platform and language-independent way. Therefore, the following is needed to pass complex parameters as part of a Web Service method:
- Provide a mechanism to marshal and unmarshal the contents of a complex Java type into an XML format that can be used as part of a SOAP message
- Deliver the marshalling and unmarshalling mechanism on both the client and the server
- Indicate in the WSDL definition that certain parameters or return values are complex types, and provide a mapping between the complex types and their associated marshalling/unmarshalling code
Mapping Complex Types with Serializers
The JAX-RPC specification defines a serialization framework that can be used to map between complex Java types and their XML representations in WSDL and SOAP. You define serializer and deserializer classes for each complex type that will be called on by the Web Service runtime to perform this conversion.
Serializers fall into three types:
- A set of standard serializers are provided as part of the Java Web Service framework. These include serializers for arrays and common classes, such as java.util.Date.
- Given a JavaBean, a generic serializer can use its getters to extract its data when marshalling, and the associated deserializer can use the setters to populate a new instance when unmarshalling.
- A custom serializer can be written to create an XML representation of any Java class.