Download What is Web Services

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
Web Service Callout: Accessing Web Service from Database.
Abhishek Khanolkar
Web services enable application to application interaction over the Web regardless of
platform (.NET etc), language (C#, Java). The main technologies of web services are
XML, SOAP, and WSDL. Web services refer to services implemented and deployed in
middle-tier application servers. Database Web services work in two directions: accessing
database resources as a Web service, and consuming external Web services from the
database itself. So, database web services consume the data in the database and use the
external web service.
This enables Information Integration. It means that you combine two communicating
programs and consume the output into the third. Also, you access the output directly from
the third tier that is the database instead of the middle-tier. This brings the application
even closer. [1]
What is Web Services?
Web services are a means of communication between different software applications.
These software applications run on a variety of platforms and/or frameworks. They are
important because of their great interoperability and extensibility. They are more
important because of their machine-process able descriptions owing to the use of XML.
They can be combined in order to achieve different operations.
Web services take many of the ideas of the Web and apply them to computer/computer
interactions. Web services communicate using a set of protocols. For these reasons
internet or WWW is responsible for the development in Web Services.
Web services differ from the World Wide Web (WWW) in scope, the scope of its
usability. HTTP and HTML were designed for interactive browsing of content that is
static, or at least highly cacheable. The Web services architecture is designed program-toprogram interactions. So, in short if you have two programs working in close coordination and the output is used by a third program, the domain could be described as a
Web Service. To interact and be platform in-dependent Web Service uses XML to
communicate between different programs. It uses the SOAP protocol for communication
and WSDL for schema definition or description.
Web services communicate using messages. The Web services architecture is built with
messages as the atomic unit of communication, which means that Web Services can
communicate only through transfer of messages between programs as a single unit. This
applies to the wire format used for message exchanges (SOAP), and also for the
descriptions of a given Web service (WSDL).
What is SOAP?
SOAP (Simple Object Access Protocol) is a protocol for exchanging XML-based
messages over computer network using HTTP. SOAP forms the foundation layer of the
Web services stack. [2]
There are different types of messaging in SOAP, the most common is the Remote
Procedure Call (RPC), in which one network node (the client) sends a request message to
another node (the server), and the server immediately sends a response message to the
client. Because of the lengthy XML format SOAP can be considerably slower than other
middleware technologies such as CORBA (Common Object Request Broker
Architecture). This is not a problem when only small messages are to be sent in Web
Services. For this reason SOAP is well suited to use in Web Service. Important thing to
understand is that Web Services is not a platform. It is a type of architecture which makes
use of different platforms and technologies. [2]
What is WSDL?
WSDL is an XML-based service description on how to communicate using the web
service. 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. The client can then use
SOAP to actually call one of the functions listed in the WSDL. [3]
What is XML?
The Extensible Markup Language (XML) is a W3C-recommended general-purpose
markup language that supports a wide variety of applications. [4]
Web Service Callout: Web Services calling from Oracle Database.
Web Service Callout refers to the invocation of Web Services from within the database.
In oracle it is done using SQL query, PL/SQL stored procedures, or Java stored
procedures. In this paper we are going to consider two databases, one Oracle and two
IBM’s DB2.
To start with we will consider the Oracle database.
The following steps are required for performing Web Service Callout in Oracle database.
A. Preparing (or Web Service enabling) the database.
B. Loading the client proxy for a particular Web Service into the database.
C. Invoking the Web Service using the proxy or wrapper, or the DII APIs. [5]
A. Preparing (or Web Service enabling) the database.
Preparing the database consists mainly in loading the Web Services client stack into the
database. This requires extra Java space inside the JavaVM to resolve and store load jar
files. The shared_pool_size=96M java_pool_size=80M.(these are the 2 parameters)
Depending on the number of Java classes already loaded into the database, the two
parameters may need to be increased beyond 96M and 80M. [6]
1. Loading the client proxy for a particular Web Service into the database:
This requires a series of multiple steps which are as follows:
This requires downloading appropriate utility, setting up the environment, and
eventually running JPublisher.
2. Download and install Callout Utility for pre-10g RDBMS:
This utility contains the jar file sqlj/lib/utl_dbws.jar, which JPublisher (downloaded in
the last step) used to generate Web Service client proxy.
3. Set up the environment to use JDK 1.3 (I might also try using JDK 1.5) .
4. Download the Web Service WSDL files and run JPublisher command to generate
the client proxy.-- use a sample Web Service available on the internet to illustrate the
command. Try www.xmethods.com.
5. Run the PL/SQL wrapper to invoke the Web Service -- The PL/SQL Wrapper
converts PL/SQL source code into an intermediate form of object code. By hiding
application internals, the Wrapper prevents misuse of your application by other
developers. [7]
B. Loading the client proxy for a particular Web Service into the database
1. Generating Proxy for Oracle 10g Database using Oracle SOAP Client –
2. Generating Proxy for Oracle 10g Database using Oracle JAX-RPC Client
3. Set up the environment to use JDK 1.4.
4. Run PL/SQL to invoke the Web Service -- In SQLPLUS, you can invoke the
PL/SQL functions provided in plsql_wrapper.sql. Each PL/SQL function corresponds to
an operation in that Web Service.
C. Invoking Web Service Using DII APIs
1. It is also possible to invoke Web Service with out generating and loading client proxy,
by using Web Service client DII APIs or PL/SQL DII APIs in SYS.UTL_DBWS.
Finally trouble shooting. And, that is the end of steps to call out web service from
database. This covers the Oracle database part, what remains is IBM’s DB2.
JPublisher: An overview.
Oracle JPublisher is a utility for converting and exchanging structured object data
between Java and SQL. JPublisher generates Java classes to represent database entities
such as SQL objects and operations, PL/SQL packages and procedures, and server-side
Java classes. The generated classes can be used through JDBC in your Java clients,
servlets, JavaServer Pages (JSP), Enterprise JavaBeans (EJB), and Web services.
JPublisher-generated classes can be exposed as Web services by the Oracle Application
Server Web Services Assembler tool. JPublisher simplifies the process of publishing
database operations as Web services as well as the process of consuming external Web
services from within the database.
JPublisher generates classes representing the following database entities:
1.
2.
3.
4.
5.
6.
7.
User-defined SQL object types.
Object reference types
User-defined SQL collection types
User-defined OPAQUE types
PL/SQL BOOLEAN.
PL/SQL RECORD and TABLE types.
PL/SQL INDEXED-BY tables
To run JPublisher on user-defined data types and PL/SQL packages in the database
that you want to convert to Java classes, you must establish a database connection to
allow access to the SQL types or PL/SQL packages you are mapping. [9]
We went into details of how a web service call out will work. Now, I will try to explain
how a real life example will look like. This example is listed in details on Oracle.com
web site.
This sample illustrates calling a Web Service from within an Oracle9i Database. The
example implemented in this demonstration is a simple purchasing system and it is
implemented like this—
 A product catalog is displayed to the user.
 The user can browse through the catalog and purchase products of interest.
 Based on the login information supplied by the user, he or she is authenticated
and the order is shipped on a later date.
 This example uses a Credit Agency Web Service which maintains a repository of
customers and their credit card information.
It all goes step by step like this –
1. The Credit Agency has a Web Service and the customer is authorized by it.
2. The order information is then added to the database.
3. The first step is to bill the customer's account. This is handled by the Credit
Agency Web Service which is invoked with the customer information and the
amount of purchase.
4. The Web Service processes the information passed to it.
5. If the amount in the customer's account is sufficient then the account is charged
with the amount and a success message is returned.
6. If the amount held in the customer's account is insufficient then the Web Service
returns back a string 'INSUFFICIENT_FUNDS' and the customer's account is
restored back to the original amount.
7. If the Web Service does not recognize the customer, it returns a fault with fault
string "INVALID_CUSTOMER".
8. The database process updates the orders table with the response from the Web
Service. When the payment is successful, the order status is changed from
"IN_SHIPPING", to "SHIPPED". If the customer's account did not have sufficient
funds, then the order status is changed to "INSUFFICIENT_FUNDS".
Retrieved from [8]
The above architecture is explained like this –
 End user browses through the product catalog and places an order.
 Information supplied by the user is first validated by the Credit Agency Web
Service and then added to the database.
 Shipping service staff selects orders to be shipped to the customers and determine
the product quantity to be shipped.
 A java stored procedure is executed to charge the customer's account whose
order is approved for shipping by the mall shipping service staff.



The customer id and the amount of purchase are passed to this stored function.
The stored function packages all the required information and communicates with
the Credit Agency Web Service.
The stored function updates the orders table with the value returned from the Web
Service. [10]
A little about Java Stored Procedures—
Java stored procedures use multiple SQL statements that run within the database and are
invoked in one call, thereby avoiding multiple calls. Java stored procedures extend
database functionality by bridging J2EE, XML, and non-J2EE worlds, using the database
as an active Web client, EJB client, and Web services client.
Java stored procedures represent an alternative to PL/SQL. Java stored procedures bring
the power and object-orientation of the Java language. [11]
Call out using DB2:
DB2 is IBM’s Relational Database management System. IBM now calls it data server.
DB2 Universal Database is a free version of database made available by IBM. The good
thing about DB2 is that it lets users download only those features essential to the user,
thus avoiding huge and hefty downloads.
“Information integration can be loosely defined as unifying data within an enterprise and
surfacing it to end users and applications as trusted information”[12].
WebSphere Information Integrator acts as a middleware and provides all the necessary
means to unifying data and providing it to the end user. In this case the data is the web
service.
IBM WebSphere Information Integration capabilities:
“Information integration is the process of integrating and transforming data and content
to deliver authoritative, consistent, timely and complete information, and governing its
quality throughout its life cycle”[14]. The main capabilities of WebSphere information
Integrator are 1. Cleanse information, 2. Connect information 3. Federate information, 4.
Transform Information and finally 5. Understand information. Information Integration
saves lot of money for example ‘The State of New Jersey
Saved an estimated $500,000 in IT development costs and expects to save as much as $8
million dollars overall by automating the information integration of data from four
disparate systems into agency specific data marts ’[14].
IBM’s RAD is originally WSAD (WebSphere Application Developer). RAD is and
Integrated Development Environment (IDE) for designing, constructing Web services,
and Java 2 Enterprise Edition (J2EE) applications. J2EE includes technologies such as
Servlets and JSP.
In any organization data can be generated from various sources. The data needs to be
consumed and the answer to that is Service Oriented Architecture (SOA). SOA makes
use of the existing data and processes and creates a new flexible model.
Checking Web Service:
The first step in the process is to check if the web service is working.
www.xmethods.com is a web site which lists many web services. Once you are on the
site you click full services link and that gives the list of all the available web services.
Then click URL of the web service and that open up the WSDL code behind the web
service. This code is opened in a web browser, copy the URL. The URL is used in the
DB2 database.
Starting DB2:
The main job of DB2 is to store the web service and call it using SQL. To start a new
sample database is created and given an alias and its schema is defined. Inside the
database create a wrapper object; in the wrapper object you define the data source as the
web service. Then you define the server definition and inside the server definition paste
the URL copied from www.xmethods.com .
Develop an Application:
Application development is done using WSAD or RAD. The database at the back is DB2
which had the web service and has been tested to work. First create a work space to work
on, and then insert a text-field on the JSP editable region. Add a button on the JSP page
and link the text field to the web service. Connect the button to action JSP which calls a
web service function. Save and run the application on server, the output will be displayed
on the JSP page. Make sure you use the web sphere V6 server. The tutorial explains this
step by step process to do the job.
Conclusion:
Calling out web service from the third tier is effective because the web service can access
the data from the database and consume it. In the other case the external web service had
to access database separately for any data. In this case the external web service is inside
the database and the data required for it to process is also inside the DB. This creates
information integration of sorts. Saving a lot of time and bringing lot applications
together. In future it is expected that more web services will be called out from database
save time and making it more reliable compared to have the callout externally.
For this reason DB2, Oracle, MYSQL are supporting the technique.
References:
1. Web services. (2006, November 1). In www.oracle.com. Retrieved, November 1,
2006, from
http://www.oracle.com/technology/tech/webservices/htdocs/dbwebservices/Database_We
b_Services.pdf
2. SOAP. (2006, November 1). http://en.wikipedia.org. Retrieved, November 1, 2006,
from http://en.wikipedia.org/wiki/SOAP
3. WSDL. (2006, November 1). http://en.wikipedia.org. Retrieved, November 1, 2006,
from http://en.wikipedia.org/wiki/Web_Services_Description_Language.
4. Extensible Markup Language. (2006, November 10). In Wikipedia, The Free
Encyclopedia. Retrieved 07:45, November 13, 2006, from
http://en.wikipedia.org/w/index.php?title=Extensible_Markup_Language&oldid=868865
62
5. Web Service Callout (2006, November). In Oracle.com Retrieved, November 3, 2006,
from http://www.oracle.com/technology/sample_code/tech/java/jsp/readme.callout.htm
6. Web Service Callout (2006, November). In Oracle.com Retrieved, November 3, 2006,
from
http://www.oracle.com/technology/sample_code/tech/java/jsp/readme.callout.htm#1._Pre
pare_the_Database
7. PL/SQL wrapper (2006, November). In http://lbdwww.epf Retrieved, November 3,
2006, from
http://lbdwww.epfl.ch/f/teaching/courses/oracle8i/server.815/a67842/c_wrap.htm
8. Credit Agency (2006, October). In Oracle.com Retrieved, October 31, 2006, from
http://www.oracle.com/technology/sample_code/tech/java/jsp/samples/wsclient/readme.h
tml#references
9. JPublisher Callout (2006, October). In Oracle.com Retrieved, October 31, 2006, from
http://www.oracle.com/technology/oramag/oracle/04-jan/o14dev_jpublisher.html
10. Credit Agency (2006, October). In Oracle.com Retrieved, October 31, 2006, from
http://www.oracle.com/technology/sample_code/tech/java/jsp/samples/wsclient/readme.h
tml#references
11. Java Stored Procedures (2006, October). In Oracle.com Retrieved, October 31, 2006,
fromhttp://www.oracle.com/technology/tech/java/java_db/pdf/OW_30820_JAVA_STOR
ED_PROC_paper.PDF
12. Java Stored Procedures (2006, September). In ibm.com Retrieved on 9/22/06
, from http://www-306.ibm.com/software/swlibrary/en_US/detail/I228969X13039L28.html
14. II (2006, September). In ibm.com Retrieved on 9/22/06
, from http://www-306.ibm.com/software/data/integration/en_US/capabilities/
15. II (2006, September). In ibm.com Retrieved on 9/22/06 , from
http://www.oracle.com/technology/products/webservices_manager/index.html