SOA and Web Services
SOA and Web Services
SOA and Web Services Tutorials in this site helps you learn more about service-oriented
architecture (SOA) and web services. In this tutorial series we will provide many examples of
Web services. You will learn how to develop, deploy and test the Web services using different
Web services engine. These days Web services are used by the organizations to integrated the
existing services and develop the new one on the top of that.
Service Oriented Architecture or SOA for short is a new architecture for the development of
loosely coupled distributed applications. In fact service-oriented architecture is collection of
many services in the network. These services communicate with each other and the
communications involves data exchange & even service coordination. Earlier SOA was based on
the DCOM or Object Request Brokers (ORBs). Nowadays SOA is based on the Web Services.
Broadly SOA can be classified into two terms: Services and Connections.
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
are 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 send a message to the service consumer. In this case a service provider can also
be a service consumer.
Different Technologies Used:
SOA is much different from point-to-point architectures. SOA comprise loosely coupled, highly
interoperable application services. These services can be developed in different development
technologies (such as Java, .NET, C++, PERL, PHP), the software components become very
reusable i.e. the same C# (C Sharp) service may be used by a Java application
and / or any other programming language. WSDL defines an standard, which encapsulates /
hides the vendor / language specific implementation from the calling client / service.
SOA definitions
(From http://en.wikipedia.org/wiki/Service-oriented_architecture )
SOA architecture enables seamless Enterprise Information Integration. Here are some of the
Benefits of the Service Oriented Architecture:
Due to its platform independence, it allows companies to use the software and
hardware of their choice .
There is no threat of vendor lock-in
SOA enables incremental development, deployment, and maintenance.
Companies can use the existing software (investments) and use SOA to build
applications without replacing existing applications
The training costs are low, so the available labor pool can be used for running the
applications
Introduction
The next generation of distributed computing has arrived. 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.
Historically speaking, remote access to binary units required platform-specific and sometimes
language-specific protocols. For example, DCOM clients access remote COM types using tightly
coupled RPC calls. CORBA requires the use of tightly coupled protocol referred to as Internet
Inter-ORB Protocol (IIOP), to activate remote types. Enterprise JavaBeans (EJBs) requires a
Remote Method Invocation (RMI) Protocol and by and large a specific language (Java). Thus
each of these remote invocation architectures needs proprietary protocols, which typically
require a tight connection to the remote source.
One can access Web services using nothing but HTTP. Of all the protocols in existence today,
HTTP is the one specific wire protocol that all platforms tend to agree on. Thus , using Web
services, a Web service developer can use any language he wish and a Web service consumer
can use standard HTTP to invoke methods a Web service provides. The bottom line is that we
have true language and platform integration . Simple Object Access Protocol (SOAP) and XML
are also two key pieces of the Web services architecture.
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-baed 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 proxy code really forwards the request to the Web service using standard
HTTP or optionally SOAP messages.
Web services are registered and announced using the following services and protocols. Many of
these and other standards are being worked out by the UDDI project, a group of industry
leaders that is spearheading the early creation and design efforts.
Universal Description, Discovery, and Integration (UDDI) is a protocol for describing available
Web services components. This standard allows businesses to register with an Internet directory
that will help them advertise their services, so companies can find one another and conduct
transactions over the Web. This registration and lookup task is done using XML and HTTP(S)-
based mechanisms.
Simple Object Access Protocol (SOAP) is a protocol for initiating conversations with a UDDI
Service. SOAP makes object access simple by allowing applications to invoke object methods or
functions, residing on remote servers. A SOAP application creates a request block in XML,
supplying the data needed by the remote method as well as the location of the remote object
itself.
Web Service Description Language (WSDL), the proposed standard for how a Web service is
described, is an XML-based service IDL (Interface Definitition Language) that defines the service
interface and its implementation characteristics. WSDL is referenced by UDDI entries and
describes the SOAP messages that define a particular Web service.
ebXML (e-business XML) defines core components, business processes, registry and repository,
messaging services, trading partner agreements, and security
.
Implementing Web Services
Even though Web services are being built using existing infrastructure, there exists a strong
necessity for a number of innovative infrastructures. The core architectural foundation of Web
services are XML, XML namespaces, and XML schema. UDDI, SOAP, WSDL, ebXML and security
standards are being developed in parallel by different vendors
has come out with a new object-oriented language C# as the development language for Web
services and .NET framework. Microsoft has an exciting tool called Visual Studio .NET in this
regard. The back end database can be Microsoft SQL Server 2000 in Windows 2000 Professional.
Sun Microsystems has its own set of technologies and tools for facilitating Web services
development. Java Servlets, Java Server Pages (JSPs), Enterprise JavaBeans (EJB) architecture
and other Java 2 Enterprise Edition (J2EE) technologies play a very critical role in developing
Web services.
There are a number of tools for developing Web services. They are Forte Java IDE, Oracle
JDeveloper, and WebGain Studio.
Sun Microsystems has taken an initiative called Sun ONE (Open Network Environment) and is
planning to push Java forward as a platform for Web services. It is developing Java APIs for XML-
based remote procedure calls and for looking up services in XML registries - two more JAX family
APIs: JAX/RPC (Java API for XML Remote Procedure Calls) and JAXR (Java API for XML Registries).
These will wrap up implementations of Web services standards, such as SOAP and UDDI.
IBM also for its part has already developed a suite of early-access tools for Web services
development. They are Web Services Toolkit (WSTK), WSDL Toolkit, and Web Services
Development Environment (WSDE).
Apache Axis is an implementation of the SOAP ("Simple Object Access Protocol") submission to
W3C.
Apache Axis is an Open Source SOAP server and client. SOAP is a mechanism for inter-
application communication between systems written in arbitrary languages, across the Internet.
SOAP usually exchanges messages over HTTP: the client POSTs a SOAP request, and receives
either an HTTP success code and a SOAP response or an HTTP error code. Open Source means
that you get the source, but that there is no formal support organization to help you when
things go wrong.
Conclusion
For the last few years, XML has enabled heterogeneous computing environments to share
information over the Web. It now offers a simplified means by which to share process as well.
From a technical perspective, the advent of Web services is not a revolution in distributed
computing. It is instead a natural evolution of XML application from structured representation of
information to structured representation of inter-application messaging.
Prior to the advent of Web services, enterprise application integration (EAI) was very difficult
due to differences in programming languages and middleware used within organizations. This
led to the situation where interoperability was cumbersome and painful. With the arrival of
Web services, any application can be integrated as long as it is Internet-enabled.
It is difficult to avoid the popularity and hype that is surrounding Web services. Each software
vendor has some initiative concerning Web services and there is always great speculation about
the future of the market for them. Whichever way it turns out, Web service architectures
provide a very different way of thinking about software development. From client-server to n-
tier systems, to distributed computing, Web service applications represent the culmination of
each of these architectures in combination with the Internet.
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.
Definition
Web services are the amalgamation of eXtensible Markup Language (XML) and HyperText
Transfer Protocol HTTP that can convert your application into a Web-application, which publish
its function or message to the rest of the world.
In other words, we can say, web services are just Internet Application Programming Interfaces
(API) that can be accessed over a network, such as Internet and intranet, and executed on a
remote system hosting the requested services.
Web-applications are simple applications that run on the web. Web services are browsers and
operating system independent service, which means it can run on any browser without the need
of making any changes. Web Services take Web-applications to the Next Level.
The World Wide Web Consortium (W3C) has defined the web services. According to W3C, “Web
Services are the message-based design frequently found on the Web and in enterprise software.
The Web of Services is based on technologies such as HTTP, XML, SOAP, WSDL, SPARQL, and
others.”
Web services use XML to code and to decode data, and SOAP to transport it (using open
protocols). Besides these, HTTP, Web Services Description Language (WSDL), Universal
Description, Discovery and Integration (UDDI), and SPARQL are the elements of Web Services.
To understand clearly about Web Services, it is mandatory to have some brief knowledge of web
services elements.
HTTP
HyperText Transfer Protocol in short HTTP is the most widely used protocol by World Wide Web.
It defines how messages are formatted and transmitted, and what actions Web servers and
browsers should take in response to various commands.
One of the shortcomings of HTTP is that it is a stateless protocol, which means each command is
executed independently, without any knowledge of the commands that came before it. This
shortcoming has been resolved in new technologies includes ActiveX, Java, JavaScript and
cookies.
Universal Description, Discovery and Integration in short UDDI is a web based distributed
directory like traditional phone book's yellow and white pages that enables businesses to list
themselves on the Internet and discover each other. It defines a registry service – a Web service
that manages information about service providers, service implementations, and service
metadata – for Web services and for other electronic and non-electronic services.
The service providers can use UDDI to advertise the services they offer while service consumers
can use UDDI to discover services.
Web Services Description Language (WSDL)
The WSDL refers to Web Services Description Language, is an XML based protocol used for
sending and receiving the information through decentralized and distributed environments.
WSDL is an integral part of UDDI that was developed jointly by Microsoft and IBM.
It defines what services are available in its Web service and also defines the methods, parameter
names, parameter data types, and return data types for the Web service. The WSDL document is
quite reliable and applications that use web services accept it
SPARQL
SPARQL refers to SPARQL Protocol and RDF Query Language is an RDF query language that
defines a standard query language and data access protocol for use with the Resource
Description Framework (RDF) data model. It works for any data source that can be mapped to
RDF. SPARQL allows a query to be consisted of triple patterns, conjunctions, disjunctions, and
optional patterns. It is standardized by the RDF Data Access Working Group (DAWG) of the W3C,
and is considered a key semantic web technology.
Web services are a set of tools that can be used in a number of ways most commonly in three
styles:
The Representational State Transfer (REST) Web Services attempts to describe architectures
based on REST can use WSDL to describe SOAP messaging over HTTP, which defines the
operations. REST describes operations, can be implemented as an abstraction purely on top of
SOAP or can be created without using SOAP at all.
In Reusable application-components uses Web Services offers most frequently used services like
currency conversion, weather reports, language translation and much more.
In Connect existing software, Web Services offers you to exchange data between different
applications and different platforms. In this type of uses, you can solve the interoperability
problem by giving different applications a way to link their data.
Now, you have assessed why web services is so popular and why it is widely in use.
In this tutorial we will develop a simple user registration Webservices. The user
registration/account registration form will be presented to the user. Once user fills in the form
and clicks on the "OK" button, the serverside JSP will call the webservice to register the user.
This webservices will expose the insert user operation which will be used by the JSP client to
register the user. We will use the NetBeans 6.1 IDE to develop and test the application.
The MySQL database is used to save the user registration data. You can modify the code to use
any database of your choice. The existing webservices can also be modified to use the Hibernate
or any other ORM technologies. You can also use the Entity beans to persist the data into
database.
Software required to develop and run this example:
JDK 1.6
NetBeans 6.1
MySQL Database 5 or above
Step 1:
Fig. 1
Step 2:
Step 3:
Fig. 4
Step 5:
Fig. 5
Step 6:
It opens a dialog box for giving the fields name of the table
Now give the field name and data type as shown below in Fig 6.
Fig. 6
Step 7:
Step 8:
Fig. 7
Step 9:
Step 10:
Fig. 9
Step 11:
Step 12:
Right Click on the project MyAccount
Select New-->WebService as shown below in Fig 10.
Fig. 10
Step 13:
Type the name of the WebService as myaccount with the package as mypack.
Click on the Finish button as shown below in Fig 11.
Fig. 11
Step 14:
Fig. 12
Step 15:
Fig. 14
Step 17:
In the choose database select the Add button as shown below in Fig 16.
Fig. 16
Step 19:
Fig. 17
Step 20:
Step 21:
Fig. 19
Step 22:
It creates the datasource data1 with the resource name as data1 in the code
Edit the code and give the database connection, statement for the mysql connectivity
as shown below.
package mypack;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.annotation.Resource;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.sql.DataSource;
@WebService()
public class myaccount {
@Resource(name = "data1")
private DataSource data1;
@WebMethod(operationName = "insert")
public String insert(@WebParam(name = "uname") String uname,
@WebParam(name = "fname") String fname,
@WebParam(name = "lname") String lname,
@WebParam(name = "location") String location,
@WebParam(name = "phone") String phone,
@WebParam(name = "credit") String credit,
@WebParam(name = "dl") String dl) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/test",
"root", "");
PreparedStatement st =
con.prepareStatement("insert into login values(?,?,?,?,?,?,?)");
st.setString(1, uname);
st.setString(2, fname);
st.setString(3, lname);
st.setString(4, location);
int ph = Integer.parseInt(phone);
st.setInt(5, ph);
int cr = Integer.parseInt(credit);
st.setInt(6, cr);
int d1 = Integer.parseInt(dl);
st.setInt(7, d1);
st.executeUpdate();
} catch (Exception e) {
System.out.println(e.getMessage());
}
return "record inserted";
}
}
Step 23:
Fig. 20
Step 24:
Fig. 21
Step 25:
Fig. 22
Step 26:
After clicking on the insert button it insert the values into the login table
It open new window and displays the Metrhod parameters, SOAP request and response
as shown below in Fig 23.
Fig. 23
Step 27:
Step 27:
Step 28:
Fig. 26
Step 29:
Step 1:
Fig. 29
Step 3:
Fig. 31
Step 5:
Fig. 33
Step 6:
After insert opoeration the code becomes like as shown below in Fig 34.
Fig. 34
Step 7:
Fig. 35
Step 8:
It runs the index.jsp in the browser as shown below in Fig 37.
Put the data and click on the ok button
Fig. 37
Step 10:
Fig. 38
Step 11:
See the data inserted in the table.
In the service tab select the connection created for mysql.
In the table node select the login
Right Click and select the view data as shown below in Fig. 39.
Fig. 39
Step 12: