Lecture 9 APIs and Web Services
Lecture 9 APIs and Web Services
<types> Defines the (XML Schema) data types used by the web
service
<binding> Defines the protocol and data format for each port type
WSDL Documents
• An example of a WSDL file is given below.
<definitions>
<message name="TutorialRequest">
<part name="TutorialID" type="xsd:string"/>
</message>
<message name="TutorialResponse"> <part name="TutorialName" type="xsd:string"/> </message>
<portType name="Tutorial_PortType">
<operation name="Tutorial">
<input message="tns:TutorialRequest"/>
<output message="tns:TutorialResponse"/> </operation> </portType>
<binding name="Tutorial_Binding" type="tns:Tutorial_PortType">
<soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="Tutorial">
<soap:operation soapAction="Tutorial"/> <
input> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:Tutorialservice" use="encoded"/> </input>
<output> <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
namespace="urn:examples:Tutorialservice" use="encoded"/> </output> </operation> </binding> </definitions>
WSDL Documents
• The important aspects to note about the above WSDL declaration are
as follows;
• <message> - The message parameter in the WSDL definition is used to define
the different data elements for each operation performed by the web service.
So in the example above, we have 2 messages which can be exchanged
between the web service and the client application, one is the
"TutorialRequest", and the other is the "TutorialResponse" operation. The
TutorialRequest contains an element called "TutorialID" which is of the type
string. Similarly, the TutorialResponse operation contains an element called
"TutorialName" which is also a type string.
• <portType> - This actually describes the operation which can be performed
by the web service, which in our case is called Tutorial. This operation can
take 2 messages; one is an input message, and the other is the output
message.
• <binding> - This element contains the protocol which is used. So in our case,
we are defining it to use http (http://schemas.xmlsoap.org/soap/http). We
also specify other details for the body of the operation, like the namespace
Universal Description, Discovery, and
Integration (UDDI)
• standard for describing, publishing, and discovering the web services that are
provided by a particular service provider.
• provides a specification which helps in hosting the information on web services.
• Platform independent, open framework.
• Uses WSDL to describe interfaces to web services.
• Seen with SOAP and WSDL as one of the three foundation standards of web
services.
• Open industry initiative enabling businesses to discover each other and define
how they interact over the Internet.
• Just as a telephone directory has the name, address and telephone number of a
particular person, the same way the UDDI registry will have the relevant
information for the web service. So that a client application knows, where it can
be found.
RESTful
• RESTful (REpresentational State Transfer) Web Service: also known as
RESTful API, is based on REST technology which is an web application
that uses HTTP requests to GET, PUT, POST and DELETE data.
• REST technology is generally preferred to the more robust Simple
Object Access Protocol (SOAP) technology because REST leverages
less bandwidth, making it more suitable for internet usage.
• With cloud use on the rise, APIs are emerging to expose web services.
REST is a logical choice for building APIs that allow users to connect
and interact with cloud services.
REST vs SOAP Web Services
REST Web Services:
• RESTful web services are stateless.
• For most servers, RESTful web services provide a good caching infrastructure over an
HTTP GET method. This can improve the performance if the information the service
returns is not altered frequently and is not dynamic.
• Service producers and consumers must understand the context and content being
passed along as there is no standard set of rules to describe the REST web services
interface.
• REST is useful for restricted-profile devices, such as mobile, for which the overhead of
additional parameters are less. REST services are easy to integrate with existing
websites and are exposed with XML so the HTML pages can consume the same with
ease. There is little need to refactor the existing site architecture. As such, developers
are more productive because they don't need to rewrite everything from scratch;
instead, they just need to add on the existing functionality.
• A REST-based implementation is simple compared to SOAP.
• REST does not enforce any message format such as XML or JSON. Whereas, SOAP is
XML based messaging protocol.
REST vs SOAP Web Services
• The Web Services Description Language (WSDL) describes a common set
of rules to define the messages, bindings, operations and location of the
service. WSDL is akin to a contract to define the interface that the
service offers.
• SOAP requires less plumbing code than REST services design (e.g.,
transactions, security, coordination, addressing and trust). Most real-
world applications are not simple and support complex operations,
which require conversational state and contextual information to be
maintained. With the SOAP approach, developers don't need to write
plumbing code into the application layer.
• SOAP web services, such as JAX-WS, are useful for asynchronous
processing and invocation.
• SOAP supports several protocols and technologies, including WSDL,
XSDs and WS-Addressing.
Web Services Advantages
• Service Reuse
• Exposing Business Functionality on the network
• Interoperability amongst applications
•A Standardized Protocol which everybody
understands
• Reduction in cost of communication