tute 4
Introduction to the web services
Web applications vs Web services
A Web service is a web application component that uses standardized format like XML to interact with other web applications over internet. Web services achieve this task with the help of XML, SOAP, WSDL and UDDI open standards.
An application that the users access over the internet is called a web application. Generally, any software that is accessed through a client web browser could be called a web application.
- Web Services can be used to transfer data between Web Applications.
- Web Services can be accessed from any languages or platform.
- A Web Application is meant for humans to read, while a Web Service is meant for computers to read.
- Web Application is a complete Application with a Graphical User Interface (GUI), however, web services do not necessarily have a user interface since it is used as a component in an application.
- Web Application can be access through browsers.
Interoperability
- Web services allow various applications to talk to each other and share data and services among themselves. Other applications can also use the web services. For example, a VB or .NET application can talk to Java web services and vice versa. Web services are used to make the application platform and technology independent.
Standardized Protocol
- Web services use standardized industry standard protocol for the communication. All the four layers (Service Transport, XML Messaging, Service Description, and Service Discovery layers) use well-defined protocols in the web services protocol stack. This standardization of protocol stack gives the business many advantages such as a wide range of choices, reduction in the cost due to competition, and increase in the quality.
Low Cost Communication
- Web services use SOAP over HTTP protocol, so you can use your existing low-cost internet for implementing web services. This solution is much less costly compared to proprietary solutions like EDI/B2B. Besides SOAP over HTTP, web services can also be implemented on other reliable transport mechanisms like FTP.
WSDL
What is WSDL?
WSDL is an XML-based file which basically tells the client application what the web service does. It is known as the Web Services Description Language (WSDL). WSDL is often used in combination with SOAP and XML Schema to provide web services over the Internet. A client program connecting to a web service can read the WSDL to determine what functions are available on the server. Any special datatypes used are embedded in the WSDL file in the form of XML Schema. The client can then use SOAP to actually call one of the functions listed in the WSDL.
Features of WSDL
- WSDL is an XML-based protocol for information exchange in decentralized and distributed environments.
- WSDL definitions describe how to access a web service and what operations it will perform.
- WSDL is a language for describing how to interface with XML-based services.
- WSDL is an integral part of Universal Description, Discovery, and Integration (UDDI), an XML-based worldwide business registry.
- WSDL is the language that UDDI uses.
Structure of the WSDL
Web Services Description Language (WSDL) is an XML grammar for describing network services as collections of communication endpoints capable of exchanging messages. The diagram below illustrates the elements that are present in a WSDL document, and indicates their relationships.
Elements in WSDL
- Types – a container for data type definitions using some type system (such as XSD).
- Message – an abstract, typed definition of the data being communicated.
- Operation – an abstract description of an action supported by the service.
- Port Type – an abstract set of operations supported by one or more endpoints.
- Binding – a concrete protocol and data format specification for a particular port type.
- Port – a single endpoint defined as a combination of a binding and a network address.
- Service – a collection of related endpoints.
PortType and operation elements
The <portType> element combines multiple message elements to form a complete one-way or round-trip operation. For example, a <portType> can combine one request and one response message into a single request/response operation. This is most commonly used in SOAP services. A portType can define multiple operations.
Element | Description |
<types> | Defines the (XML Schema) data types used by the web service |
<message> | Defines the data elements for each operation |
<portType> | Describes the operations that can be performed and the messages involved. |
<binding> | Defines the protocol and data format for each port type |
Binding and Service Elements
The <binding> element provides specific details on how a portType operation will actually be transmitted over the wire.
- The bindings can be made available via multiple transports including HTTP GET, HTTP POST, or SOAP.
- The bindings provide concrete information on what protocol is being used to transfer portType operations.
- The bindings provide information where the service is located.
- For SOAP protocol, the binding is <soap:binding>, and the transport is SOAP messages on top of HTTP protocol.
- You can specify multiple bindings for a single portType.
The binding element has two attributes : name and type attribute.
<binding name = “Hello_Binding” type = “tns:Hello_PortType”>
The name attribute defines the name of the binding, and the type attribute points to the port for the binding, in this case the “tns:Hello_PortType” port.
The <service> element defines the ports supported by the web service. For each of the supported protocols, there is one port element. The service element is a collection of ports.
- Web service clients can learn the following from the service element −
- where to access the service,
- through which port to access the web service, and
- how the communication messages are defined.
- The service element includes a documentation element to provide human-readable documentation.
SOAP
How SOAP is used with HTTP
SOAP is a messaging protocol and in a nutshell is just another XML language.
Its purpose is the data exchange over networks. Its concern is the encapsulation of these data and the rules for transmitting and receiving them.
Its purpose is the data exchange over networks. Its concern is the encapsulation of these data and the rules for transmitting and receiving them.
HTTP is an application protocol and SOAP messages are placed as the HTTP payload.
Although there is the overhead of HTTP, it has the advantage that it is a protocol that is open to firewalls, well-understood and widely-supported.
Although there is the overhead of HTTP, it has the advantage that it is a protocol that is open to firewalls, well-understood and widely-supported.
You will get good knowledge about this by referring given URL ;http://www.informit.com/articles/article.aspx?p=169106&seqNum=7
How SOAP can be used for functional oriented communication?
The concept of routing a message through a string of nodes that perform different functions is how SOAP supports things like addressing, security and format-independence. Essentially, the headers identify roles, which in turn provide the SOA features which SOAP then routes to. Stringing messages through a sequence of steps is uncommon in today’s microservice-centric development environments.
Structure of SOAP message
One thing to note is that SOAP messages are normally auto-generated by the web service when it is called.
Whenever a client application calls a method in the web service, the web service will automatically generate a SOAP message which will have the necessary details of the data which will be sent from the web service to the client application.
A simple SOAP Message has the following elements
- The Envelope element
- The header element and
- The body element
- The Fault element (Optional)
SOAP Attachment
You can associate a SOAP message with one or more attachments in their native format (for example GIF or JPEG) by using a multipart MIME structure for transport. There are two main standards that define how to do this:
- SOAP Messages with Attachments W3C Note. This document defines specific use of the Multipart/Related MIME media type, and rules for the use of URI references to refer to entities bundled within the MIME package. It outlines a technique for a SOAP 1.1 message to be carried within a MIME multipart/related message in such a way that the SOAP processing rules for a standard SOAP message are not changed.
- Web Services-Interoperability (WS-I) Attachments Profile Version 1.0. This profile compliments the WS-I Basic Profile 1.1 to add support for conveying interoperable attachments with SOAP messages. There are two main parts to this profile:
- An introduction to the XML Schema type swaref (SOAP with attachments reference). This is used to define content within the SOAP body that refers to attachments within the message.
- A definition of how a WSDL message part that is bound to a MIME attachment is encoded into the SOAP message.
MIME header
MIME headers come in two flavors: MIME message headers and MIME part headers. MIME message headers are just additional RFC 822-style message headers. They denote that a message is MIME compliant and inform a receiving MUA of the structure and encoding of the message. MIME part headers reside in a message body and describe the contents of each part of a multipart message.
If a MIME header is part of a message header block, it applies to the entire message. If it appears at the beginning of a message part, it applies only to that part.
MIME message headers are:
- MIME-Version
- Content-Type
- Content-Transfer-Encoding
- Content-ID
- Content-Description
- Content-Disposition (experimental)
Different set of Frameworks/libraries for SOAP
Name | Platform | Protocols |
WSO2 WSF/PHP | PHP | SOAP, WSDL |
XFire became Apache CXF | Java | SOAP, WSDL |
XML Interface for Network Services | Java | SOAP, XML-RPC, WSDL, JSON-RPC, JSON |
Dframe Framework | PHP | JSON, REST |
Implement SOAP services
Annotations in JAX-WS
Annotations are used in mapping Java to WSDL and schema, and at run-time to control how the JAX–WS run-time processes and responds to web service invocations.
@WebService
- The @WebService annotation marks a Java class as implementing a Web service or marks a service endpoint interface (SEI) as implementing a web service interface.
@SOAPBinding
- The @SOAPBinding annotation specifies the mapping of the web service onto the SOAP message protocol. Apply this annotation to a type or methods on a client or server Service Endpoint Interface (SEI) or a server endpoint implementation class.
@WebMethod
- The @WebMethod annotation denotes a method that is a web service operation. Apply this annotation to methods on a client or server Service Endpoint Interface (SEI) or a server endpoint implementation class.
@WebResult
- The @WebResult annotation customizes the mapping of a return value to a WSDL part or XML element. Apply this annotation to methods on a client or server Service Endpoint Interface (SEI) or a server endpoint implementation class.
@Oneway
- The @Oneway annotation denotes a method as a web service one-way operation that only has an input message and no output message. Apply this annotation to methods on a client or server Service Endpoint Interface (SEI) or a server endpoint implementation class.
@WebParam
- The @WebParam annotation customizes the mapping of an individual parameter to a web service message part and XML element. Apply this annotation to methods on a client or server Service Endpoint Interface (SEI) or a server endpoint implementation class.
@HandlerChain
- The @HandlerChain annotation associates the web service with an externally defined handler chain. You can only configure the server side handler by using the @HandlerChain annotation on the Service Endpoint Interface (SEI) or the server endpoint implementation class.
@RequestWrapper
- The @RequestWrapper annotation supplies the JAXB generated request wrapper bean, the element name, and the namespace for serialization and deserialization with the request wrapper bean that is used at runtime. When starting with a Java object, this element is used to resolve overloading conflicts in document literal mode. Only the
className
attribute is required in this case
@ResponseWrapper
- The @ResponseWrapper annotation supplies the JAXB generated response wrapper bean, the element name, and the namespace for serialization and deserialization with the response wrapper bean that is used at runtime. When starting with a Java object, this element is used to resolve overloading conflicts in document literal mode. Only the
className
attribute is required in this case.
for more information with examples ;https://examples.javacodegeeks.com/enterprise-java/jws/jax-ws-annotations-example/
Testing of web services is one of the important type of software testing approach, which is mainly used to determine the expectations for reliability, functionality, performance, etc.
As these days Automated testing is considered as one of the most trending methodology in the field of software testing, hence testing web apps based on RESTful APIs through automation will provide effective test results. Some of the best & popular tools for web services testing are:
- SoapUI,
- TestingWhiz,
- SOATest
- TestMaker,
- Postman, etc.
Comments
Post a Comment