Lesson3 Web Services
Lesson3 Web Services
Web Services
Lesson 3: Web Services
_____________________________________________________________________________
One of key definitions of Web Services is: "Web Services are loosely coupled software
components delivered over Internet-standard technologies." Some of the early products in Web
Services started appearing in 1997 when Sun announced its Jini platform and Hewlett-Packard
its e-speak. After that, many big players such as IBM and Microsoft joined this race. The Web
Services arena picked up steam after the big players roped in and several small players also
joined hands for what was perceived as the next Internet wave.
Two of the key problems solved by Web Services over earlier distributed systems such as
CORBA, DCOM, RPC, and so forth were:
One of the primary concerns of Web-based programmers was how to transmit data in an
interoperable manner. At the bottom-most layer is the XML standard that addresses this. SOAP
(Simple Object Access Protocol) is an XML-based mechanism for messaging and RPC (Remote
Procedure Calls). It addresses the fundamental problem of firewall traversal in RPC systems by
using HTTP as the transport. SOAP is the protocol used for invoking the service.
tools provided by many different vendors - to create applications that use a combination of
software modules called from systems in disparate departments or from other companies.
A Web service contains some number of classes, interfaces, enumerations and structures that
provide black box functionality to remote clients. Web services typically define business objects
that execute a unit of work (e.g., perform a calculation, read a data source, etc.) for the
consumer and wait for the next request. Web service consumer does not necessarily need to be
a browser-based client. Console-based and Windows Forms-based clients can consume a Web
service. In each case, the client indirectly interacts with the Web service through an intervening
proxy. The proxy looks and feels like the real remote type and exposes the same set of
methods. Under the hood, the the proxy code really forwards the request to the Web service
using standard HTTP or optionally SOAP messages.
Exposing the function on to network: A Web service is a unit of managed code that can be
remotely invoked using HTTP, that is, it can be activated using HTTP requests. So, Web
Services allows you to expose the functionality of your existing code over the network. Once it
is exposed on the network, other application can use the functionality of your program.
Connecting Different Applications: Web Services allows different applications to talk to each
other and share data and services among themselves. Other applications can also use the
services of the web services. For example VB or .NET application can talk to java web services
and vice versa. So, Web services is used to make the application platform and technology
independent.
Standardized Protocol: Web Services uses standardized industry standard protocol for the
communication. All the four layers (Service Transport, XML Messaging, Service Description and
Service Discovery layers) uses the well defined protocol in the Web Services protocol stack. This
standardization of protocol stack gives the business many advantages like wide range of
choices, reduction in the cost due to competition and increase in the quality.
Low Cost of communication: Web Services uses SOAP over HTTP protocol for the
communication, 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.
Support for Other communication means: Beside SOAP over HTTP, Web Services can also be
implemented on other reliable transport mechanisms. So, it gives flexibility use the
communication means of your requirement and choice. For example Web Services can also be
implemented using ftp protocol (Web services over FTP).
Loosely Coupled Applications: Web Services are self-describing software modules which
encapsulates discrete functionality. Web Services are accessible via standard Internet
communication protocols like XML and SOAP. These Web Services can be developed in any
technologies (like c++, Java, .NET, PHP, Perl etc.) and any application or Web Services can
access these services. So, the Web Services are loosely coupled application and can be used by
applications developed in any technologies. For example, I have heard of people developing
Web Services using Java technologies and using the Web Services in VB or .NET applications.
Web Services Sharing: These days due to complexness of the business, organizations are using
different technologies like EAI, EDI, B2B, Portals etc. for distributing computing. Web Services
supports all these technologies, thus helping the business to use existing investments in other
technologies.
Web Services are Self Describing: Web Services are self describing applications, which reduces
the software development time. This helps the other business partners to quickly develop
application and start doing business. This helps business to save time and money by cutting
development time.
Automatic Discovery: Web Services automatic discovery mechanism helps the business to easy
find the Service Providers. This also helps your customer to find your services easily. With the
help of Web Services your business can also increase revenue by exposing their own Web
Services available to others.
Business Opportunity: Web Services has opened the door to new business opportunities by
making it easy to connect with partners.
Services:
A service is a function or some processing logic or business processing that is well-defined, self-
contained, and does not depend on the context or state of other services. Example of Services
is Loan Processing Services, which can be self-contained unit for process the
Loan Applications. Other example may be Weather Services, which can be used to get the
weather information. Any application on the network can use the service of the Weather Service
to get the weather information.
Connections:
Connections means the link connecting these self-contained distributed services with each
other, it enable client to Services communications. In case of Web services SOAP over HTTP is
used to communicate the between services.
The following figure is a typical example of the service-oriented architecture. It shows how a
service consumer sends a service request to a service provider. After accepting the request,
service provider sends a message to the service consumer. In this case a service provider can
also be a service consumer.
KEY POINTS:
Web Services can convert your applications into Web-applications.
Web Services can be used by other applications.
The basic Web Services platform is XML + HTTP.
Before you continue you should have a basic understanding of the following:
HTML
XML
The HTTP protocol is the most used Internet protocol.
XML provides a language which can be used between different platforms and programming
languages and still express complex messages and functions.
services from various sources that work together regardless of where they reside or how they
were implemented.
XML makes it possible for developers to expose valuable resources in a highly interoperable
fashion, where a resource is any type of application or data store used within an organization.
The XML Web services architecture defines a standard mechanism for making resources
available via XML messaging. Being able to access a resource by simply transmitting XML
messages over standard protocols like TCP, HTTP, or SMTP greatly lowers the bar for potential
consumers. The term "Web service" typically refers to the piece of code implementing the XML
interface to a resource, which may otherwise be difficult to access
This architecture makes it possible for any consumer with XML support to integrate with Web
service applications.
There are probably as many definitions of XML Web Service as there are companies building
them, but almost all definitions have these things in common:
XML Web Services expose useful functionality to Web users through a standard Web protocol.
In most cases, the protocol used is SOAP.
XML Web services provide a way to describe their interfaces in enough detail to allow a user to
build a client application to talk to them. This description is usually provided in an XML
document called a Web Services Description Language (WSDL) document.
XML Web services are registered so that potential users can find them easily. This is done with
Universal Discovery Description and Integration (UDDI).
3.3.1 SOAP
Soap is the communications protocol for XML Web services. When SOAP is described as a
communications protocol, most people think of DCOM or CORBA and start asking things like,
"How does SOAP do object activation?" or "What naming service does SOAP use?" While a
SOAP implementation will probably include these things, the SOAP standard doesn't specify
them. SOAP is a specification that defines the XML format for messages.
There are other parts of the SOAP specification that describe how to represent program data as
XML and how to use SOAP to do Remote Procedure Calls.
Most current implementations of SOAP support RPC applications because programmers who are
used to doing COM or CORBA applications understand the RPC style. SOAP also supports
document style applications where the SOAP message is just a wrapper around an XML
document. Document-style SOAP applications are very flexible and many new XML Web services
take advantage of this flexibility to build services that would be difficult to implement using
RPC.
A major source of confusion when getting started with SOAP is the difference between the
SOAP specification and the many implementations of the SOAP specification. Most people who
use SOAP don't write SOAP messages directly but use a SOAP toolkit to create and parse the
SOAP messages. These toolkits generally translate function calls from some kind of language to
a SOAP message. For example, the Microsoft SOAP Toolkit 2.0 translates COM function calls to
SOAP and the Apache Toolkit translates JAVA function calls to SOAP.
One of the first questions newcomers to SOAP ask is how does SOAP deal with security. Early in
its development, SOAP was seen as an HTTP-based protocol so the assumption was made that
HTTP security would be adequate for SOAP. When SOAP expanded to become a more general-
purpose protocol running on top of a number of transports, security became a bigger issue. For
example, HTTP provides several ways to authenticate which user is making a SOAP call, but
how does that identity get propagated when the message is routed from HTTP to an SMTP
transport? SOAP was designed as a building-block protocol, so fortunately, there are already
specifications in the works to build on SOAP to provide additional security features for Web
services. The WS-Security specification defines a complete encryption system.
AN OVERVIEW OF SOAP
3.3.2 UDDI
Universal Discovery Description and Integration is the yellow pages of Web services.A UDDI
directory entry is an XML file that describes a business and the services it offers. There are
three parts to an entry in the UDDI directory. The "white pages" describe the company offering
the service: name, address, contacts, etc. The "yellow pages" include industrial categories
based on standard taxonomies.
The "green pages" describe the interface to the service in enough detail for someone to write
an application to use the Web service. The way services are defined is through a UDDI
document called a Type Model or tModel. In many cases, the tModel contains a WSDL file that
describes a SOAP interface to an XML Web service,.The UDDI directory also includes several
ways to search for the services you need to build your applications. For example, you can
search for providers of a service in a specified geographic location or for business of a specified
type. The UDDI directory will then supply information, contacts, links, and technical data to
allow you to evaluate which services meet your requirements.
OVERVIEW OF UDDI
• UDDI is a directory service where businesses can register and search for Web services.
• UDDI is a directory for storing information about web services
• UDDI is a directory of web service interfaces described by WSDL
• UDDI communicates via SOAP
• UDDI is built into the Microsoft .NET platform
3.3.3 WSDL
WSDL (often pronounced whiz-dull) stands for Web Services Description Language. For our
purposes, we can say that a WSDL file is an XML document that describes a set of SOAP
messages and how the messages are exchanged. In other words, WSDL is to SOAP what IDL is
to CORBA or COM. Since WSDL is XML, it is readable and editable but in most cases, it is
generated and consumed by software. Since WSDL is a machine-readable language (e.g., it's
just an XML file), tools and infrastructure can be easily built around it. Today developers can
use WSDL definitions to generate code that knows precisely how to interact with the Web
service it describes. The notation that a WSDL file uses to describe message formats is based
on the XML Schema standard which means it is both programming-language neutral and
standards-based which makes it suitable for describing XML Web services interfaces that are
accessible from a wide variety of platforms and programming languages. In addition to
describing message contents, WSDL defines where the service is available and what
communications protocol is used to talk to the service. This means that the WSDL file defines
everything required to write a program to work with an XML Web service
WSDL plays an important role in the overall Web services architecture since it describes the
complete contract for application communication (similar to the role of IDL in the DCOM
architecture). Although other techniques exist for describing Web services, the WS-I Basic
Profile Version 1.0 mandates the use of WSDL and XML Schema (see Figure 4) for describing
Web services. This helps ensure interoperability at the service description layer.
OVERVIEW OF WSDL
WSDL is an XML-based language for describing Web services and how to access them.
WSDL stands for Web Services Description Language
WSDL is written in XML
WSDL is an XML document
WSDL is used to describe Web services
WSDL is also used to locate Web services
A WSDL definition is an XML document with a root definition element from the
http://schemas.xmlsoap.org/wsdl/ namespace.. The definitions element may contain several
other elements including types, message, portType, binding, and service, all of which come
from the http://schemas.xmlsoap.org/wsdl/ namespace.
The first three elements (types, message, and portType) are all abstract definitions of the
Web service interface. These elements constitute the programmatic interface that you typically
interface with in your code. The last two elements (binding and service) describe the
concrete details of how the abstract interface maps to messages on the wire.
WSDL Elements
types A container for abstract type definitions defined using XML Schema
binding A concrete protocol and data format specification for a particular portType
3.5.1 Annotation
An annotation is an XML document (an instance document) that contains the actual data of an
annotation. Every annotation has an associated annotation type, and the annotation is an
instantiation of the corresponding annotation structure. In other words, an annotation specifies
values for all of the fields defined by the annotation's structure. Within this API, annotations are
identified by globally unique identifiers (GUIDs). Many annotations can share the same
annotation type and structure.
The following example will describe how to write, deploy and run a webservice using the
Editplus /netbeans IDE, JBOSS application server and the ANT tool.
There are three steps involved in writing a webservice.
@WebService(name="Calculator1")
@SOAPBinding(style=Style.RPC)
public interface Calculator extends Remote
{
@WebMethod int add(int x, int y);
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;
import java.net.URL;
import java.io.File;
public class Client
{
public static void main(String[] args) throws Exception
{
URL url = new
URL("http://localhost:8080/tutorial/CalculatorBean?wsdl");
QName qname = new QName("http://webservice1/",
"CalculatorBeanService");
ServiceFactory factory = ServiceFactory.newInstance();
Service service = factory.createService(url, qname);
Calculator calculator = (Calculator)
service.getPort(Calculator.class);
System.out.println("1 + 1 = " + calculator.add(1, 1));
System.out.println("1 - 1 = " + calculator.subtract(1, 1));
}
}
Build Secure Web Services Easily: As well as an easy and intuitive API design, the objective
here was to abstract common best practices when securing end-to-end messages. From having
spoken to hundreds of existing WSE customers, there emerged five common scenarios for
message-level security
3.8 Summary
• SOA (Service oriented Architecture) is a new architecture for the development of loosely
coupled distributed applications. A service-oriented architecture is a collection of many
services in the network.
• XML Web services are becoming the platform for application integration. Applications are
constructed using multiple XML Web services from various sources that work together
regardless of where they reside or how they were implemented. Soap is the
communications protocol for XML Web services.
• Universal Discovery Description and Integration is the yellow pages of Web services.A
UDDI directory entry is an XML file that describes a business and the services it offers.
• A WSDL (Web Services Description Language) file is an XML document that describes a
set of SOAP messages and how the messages are exchanged. WSDL plays an important
role in the overall Web services architecture since it describes the complete contract for
application communication.