With the bottom-up development approach, you start with one or more database objects to create and expose as Web service operations. Working with a table, a view, or a procedure, you can expose these objects as Web service operations directly from the Server Explorer in the Microsoft Visual Studio environment. This is easy-to-use functionality, as it involves a one-click approach in generating and exposing IBM Data Web Services.
In order to create IBM data server Web service applications, you need to have the following installed:
- Microsoft Visual Studio 2005/ Visual Studio 2008 Professional Edition
- IBM database client V9.5 or later
- IBM Database Add-Ins for Visual Studio, Version 9.5 or later
- Access to any IBM DB2 or Informix database
- Any of the following application servers:
- Apache Tomcat V5.5
- IBM WebSphere® Application Server Community Edition 1.1
- IBM WebSphere Application 6.x
General familiarity with the IBM Database Add-ins for Visual Studio is also assumed. To become more familiar with the general features of the IBM Database Add-Ins for Visual Studio, read the "DB2 for Visual Studio 2005 developers, Part 1: Overview of IBM Database Add-ins for Visual Studio 2005" (developerWorks, December 2005) and the Develop proof-of-concept .NET applications tutorial series (developerWorks).
New users to IBM Data Web Services and .NET framework can get acquainted to this new technology by following this useful tutorial: "IBM Data Studio Data Web Services, Part 1: IBM Data Studio: Get started with Data Web Services" (developerWorks, November 2007).
Creating an IBM Data Web Service
This article covers operations permitted on different nodes under IBM Data Server connection that support IBM Data Server Web Services and the steps needed to run these operations. This article also covers the creation of a sample scenario in which you can create a Web service with multiple operations and how it can be deployed.
- To begin, launch Visual Studio 2005 or Visual Studio 2008, and create a connection to the database.
- From the pop-up menu, select Add Connection in Server Explorer,
which launches the Add connection dialog, as shown in Figure1:
Figure 1. Add connection
- In the "Data source" field, select IBM DB2, IDS and U2 Servers (IBM DB2, IDS, and U2 Data Provider for .NET Framework), and provide server name, user ID, and password.
- Click on the Test Connection button to verify if the connection
has been made successfully, then click on the OK button.
Figure 2. Add connection
The Web Services node is shown under the connection. If there are any existing Web services, they are listed under the Web Services node.
Figure 3. Server Explorer
- You can right-click on a table, view, or procedure in the Server
Explorer and select Create and Deploy IBM Data Web Service from
the context menu to create an IBM Data Web Service operation. Doing so
launches the IBM Data Web Service Designer, allowing you to create a
new data Web service.
Figure 4. Creating an IBM Data Web Service
You can also launch the same designer (IBM Data Web Service Designer) from the Web Services node in the Server Explorer:
Figure 5. Creating an IBM Data Web Service
- You can edit an existing Web service to rename, add, delete, or modify
a Web service operation. To do so, select the Web service in Server
Explorer, right-click on the Web service, and select Open
Definition, which launches the IBM Data Web Service Designer:
Figure 6. Modify Web service
Within the designer, you can edit different attributes of th Web service:
Figure 7. Edit Web service
- To run a Web service, select Run from the context menu. Doing
so launches the Web Service Method Invocation dialog, where you can
select any operation, enter associated parameter values, and see the
WSDL (Web Services Description Language) and the returned XML data.
Figure 8. Run Web service
- To delete a Web service and its related artifacts from the server, select Delete from the context menu.
IBM Data Web Service Designer
This designer allows you to create a Web service in one single step. You can also use this same designer to modify or edit a Web service. The designer consists of two views:
- Web service information view (default view)
- Show generated WSDL — In this view, you can modify the server parameter settings or point to a different server. Any action on this dialog is persisted, and you do not have to remember it again. When you launch this dialog for the first time, the default parameter for the server type is set for you, though you can change that at any time.
Figure 9. IBM Data Web Service Designer
Let's create a sample Web service for Employees table with the following table definition to store employee records:
Listing 1. Table definition
sqltype sqlname.data -------------------- ------------ CHARACTER EMPNO VARCHAR FIRSTNME CHARACTER MIDINIT VARCHAR LASTNAME CHARACTER WORKDEPT CHARACTER PHONENO DATE HIREDATE CHARACTER JOB SMALLINT EDLEVEL CHARACTER SEX DATE BIRTHDATE DECIMAL SALARY DECIMAL BONUS DECIMAL COMM VARCHAR FOR BIT DATA PKEY XML PROJECTS
Let's also use a stored procedure called
Bonus_Increase with the following parameters
(these objects are available as part of the sample database).
Listing 2. Generated code
IN p_bonusFactor DECIMAL (3,2) IN p_bonusMaxSumForDept DECIMAL (9,2), OUT p_deptsWithoutNewBonuses VARCHAR(255), OUT p_countDeptsViewed INTEGER, OUT p_countDeptsBonusChanged INTEGER, OUT p_errorMsg VARCHAR(255)
Right-click on the procedure Bonus_Increase, and select Create and Deploy IBM Data Server Web Service. This launches the IBM Data Server Web Service Designer.
The default name (Webservice1) is assigned to the Web service and is shown in the name field of the designer.
Tooling automatically generates the
operation with the operation text as
So far, only one Web service with one operation has been created. To add
more operations for this simple service, click on the plus (+)
button in front of the operation grid and specify names for the
operations. For example, this sample uses
getEmployee for the new operation being added.
You can assign the operation in operation column, or you can click on the
ellipses to bring up the Operation edit dialog, where you can type owner
name. The editor lists all possible objects using intellisense. Select
table name (Employees table for this sample), and click on OK.
Since this is a table operation, tooling generates
delete operations automatically. The tooling
calls the employee
insertEmployee and the
updateEmployee, and so on. For this sample
service, you do not need the
update operations, so click on the rows in the
operation grid for
update, and click on the minus (-)
button in front of grid to remove those operations.
Listing 3 shows the
SELECT statement for the
getEmployee operation for the Employee table,
as generated by the tooling:
SELECT * FROM EMPLOYEE WHERE EMPNO = ?
Listing 4 shows the generated
INSERT INTO EMPLOYEE values (?, ?, ?, ?, ?, ?, ?,? , ?,? ,?,?, ?,?, ?, ?)
Since this is the first time the IBM Data Web Service Designer is launched, the Advanced Option dialog appears so you can enter application server deployment and configuration information. Since the tooling persists all changes to this Advanced Options dialog for later use, you only need to enter this information once.
Figure 10. Advanced Options
Setting up an application server
The sample scenario in this article uses IBM WebSphere Application Server Community Edition 1.1.
- Start WebSphere Application Server Community Edition 1.1 server and
launch its Administrative Console:
Figure 11. Administrative Console
- Click on the Database Pools link from the Console Navigation
panel (this launches Database Pools page):
Figure 12. Administrative Console
- Click on the Using the Geronimo database pool wizard link:
Figure 13. Database Pools
Samplein the Name of Database Pool field, and click on Next:
Figure 14. Database Pools
- Select the appropriate database driver for type of DB2 server and fill
out the rest of the fields, then enter
samplefor database field and click on Next:
Figure 15. Database Pools
- On the last page of the Database Pools wizard, click on Test
Connection to ensure the connection information is correct and
connection to your DB2 Sample database can be established:
Figure 16. Database Pools
- Once the test connection is successful, click on Deploy to
create the database pool:
Figure 17. Database Pools
- After the database pool is created, close the Administrator Console page and shut down WebSphere Application Server Community Edition server.
- Go back to the IBM Web Service Designer in Visual Studio, and click on
Figure 18. Advanced Options
- In the Advanced Option dialog, select New, which launches the
New Server dialog:
Figure 19. New Server
- Select IBM from the Vendor drop-down list, and click on Browse to specify you Web server installation directory.
- Point to you WebSphere Application Server Community Edition1.1
installation directory, then click OK to complete the new
Figure 20. Advanced Options
- Change the name of the artifact.dataSourceGroupId file to the name of the database pool you created in the previous step in the Advanced Options console page, which was "sample".
- Check the Set As Default and Open Invoke Web Service Method dialog check boxes. The first check box allows tooling to reuse the same information for further Web service deployment, and the second check box launches Web Service test dialog after deployment is successful.
- Click OK in this dialog to persist this information:
Figure 21. IBM Data Web Service Designer
- Once you're finished with the new server setup, click on the Save toolbar button in Visual Studio IDE to deploy the Web service.
The deployment process takes a minute for the first time, but any subsequent deployments are fast. IBM Web Service Designer prints out each deployment step into the Visual Studio Output window:
Figure 22. Deployment output messages
After successful deployment, Web Service Method Invocation dialog is launched, allowing you to test the Web service you just deployed:
Figure 23. Web Service Method Invocation
You can also click on Show Script to see the WSDL generated for the Web service.
IBM Database Add-ins for Visual Studio provides support for IBM Data Web Services, which is the next generation Web service provider for IBM database servers. The tooling provides an easy way to create and expose Web service operations for the selected database objects. It supports the IBM family of database servers and many popular Web servers, such as Apache Tomcat V5.5 and IBM WebSphere Application Server V6.1 and Community Edition V1.1. The add-ins provide a framework to assist the users in creating Web services to meet business needs. As illustrated in this article, you can create, view, modify, and delete Web services without writing extensive code, and you can deploy these Web services with ease.
- "DB2 for Visual Studio 2005 developers, Part 1: Overview of IBM Database Add-ins for Visual Studio 2005" (developerWorks, December 2005): Get an overview of the new functionality provided by IBM for Visual Studio 2005.
- Develop proof-of-concept .NET applications tutorial series (developerWorks): Create proof-of-concept applications to access relational and XML data in IBM DB2 9, using Microsoft Visual Studio .NET 2005.
- "IBM Data Studio Data Web Services, Part 1: IBM Data Studio: Get started with Data Web Services" (developerWorks, November 2007): Follow this a step-by-step guide to creating your first Data Web Service using IBM Data Studio.
9.5 Information Center for Linux, UNIX, and Windows:
Find information describing how to use the DB2 family of products and
features, as well as related WebSphere Information Integration products
- IBM Database Add-Ins for Visual Studio Overview: Read more about the features that are available in the IBM Database Add-ins.
- developerWorks IBM Information Management and Visual Studio .NET: Find more resources for DB2 .NET developers.
- DB2 for .NET: Innovate with Visual Studio. Find more information on the IBM Database Add-Ins for .NET.
- developerWorks Information Management zone: Learn more about Information Management. Find technical documentation, how-to articles, education, downloads, product information, and more.
- Stay current with developerWorks technical events and webcasts.
- Technology bookstore: Browse for books on these and other technical topics.
Get products and technologies
- Build your next development project with IBM trial software, available for download directly from developerWorks.
- Participate in the discussion forum.
- Participate in developerWorks blogs and get involved in the developerWorks community.
Dig deeper into Information management on developerWorks
Get samples, articles, product docs, and community resources to help build, deploy, and manage your cloud apps.
Keep up with the best and latest technical info to help you tackle your development challenges.
Software development in the cloud. Register today to create a project.
Evaluate IBM software and solutions, and transform challenges into opportunities.