Skip to main content

skip to main content

developerWorks  >  Rational | SOA and Web services  >

Creating and Consuming Web Services Using IBM Rational Business Developer (EGL)

developerWorks
Go to the previous pagePage 3 of 9 Go to the next page

Document options
PDF format - Fits A4 and Letter

PDF - Fits A4 and Letter
3428 KB (9 pages)

Get Adobe® Reader®


My developerWorks needs you!

Connect to your technical community


Rate this tutorial

Help us improve this content


Creating EGL Web services

The steps you will perform in this section are:

  1. Configure a project for Web services: Create a project and set its properties to allow Web service development and testing.
    1. Specify workspace capabilities
    2. Specify Web service-specific build options
  2. Define an EGL Web service: Create a new EGL service file.
  3. Code the Web service business logic: In the EGL Service file you create, add EGL functions and variables (statements) that perform the service (for example, business logic) required by your application.
  4. Generate the Web service interactively: Test your Web service interactively using the Web Service Explorer tools.

You need to start the Rational Developer for System i SOA workbench, and select a workspace that will contain all of the files that you use for your development project.

First Steps

You will use a new workspace so that your environment matches that used when this script was created.

Start Rational Developer for System i SOA V7.1 (or later)

  1. Click the Start > All programs > IBM Software Development Platform > IBM Rational Business Developer for System i > IBM Rational Business Developer for System i menu item, as shown in Figure 3.

Figure 3. Start Rational Developer for System i
menu command
  1. When prompted for a Workspace name, enter a new name, as shown in Figure 4, so that you get a brand new workspace.

Figure 4. Workspace Launcher dialog
drop-down list and Use as default check box option

Tip: Don’t worry about the directory path: accept the default. Specify a unique directory for the workspace.

  1. Click the OK button.

The workbench will look like that shown in Figure 5.

  1. Click the x on the Welcome tab, to close the Welcome page.

Figure 5. Close the Welcome tab
menu bar, tab, and icons


Back to top


Configure an EGL Web project

In the Rational Developer for System i SOA workbench, you will be using the Web perspective with all of the views and editors required to work with a Web application.

  1. Switch to the Web perspective: Click the Open Perspective icon on the top right hand side of the workbench.
  1. Select Other, as shown in Figure 6.

Figure 6. Switch to the Web perspective
menu command

The Open Perspective dialog displays.

  1. Select Web from the list of perspectives, as shown in Figure 7.

Figure 7. Open Perspective dialog
tree view

You are now ready to create a new EGL project.

  1. On the the workbench menu, click File > New > Other, as shown in Figure 8

Figure 8. Create a new project
menu command
  1. in the Select a wizard dialog that appears (Figure 9).
    1. Expand the EGL node.
    2. Select EGL Project.
    3. Click the Next button.

Figure 9. EGL Project wizard
List of available wizards in tree view
  1. In the New EGL Project (Figure 10):
    1. Name the project LAB71_Service.radio button
    2. Be sure to select the Web Project
    3. Click the Next button

Figure 10. Enter the name and type for the project
Project type options are Web, General, or Plug-in


Back to top


Define an EGL Web service

  1. Modify the default EGL Web project settings, as shown in Figure 11.
    1. Select Create new project build descriptor.
    2. Leave the Show Advanced Settings check box. clear.
    3. Click the Finish button.

Figure 11. Specify Target Runtime and Build Descriptor Options
Drop-down list and radio button options

Check EGL build file to see if serverType property is defined:

  • In Project Explorer, expand Lab71_Service project tree by clicking on the '+' sign.
    1. Lab71_Service -> EGLSource
    2. Double click on Lab71_Service.eglbld file
    3. Check if serverType property is defined as shown below:

Figure 11a. Check serverType property
Check if serverType property is defined
  • If this property is not defined, EGL code generation will fail in subsequent steps.
  • To define serverType property do following steps:
    1. Uncheck Show only specified options check box to display all properties.

Figure 11b. Unchecking checkbox to display properties
Uncheck Show only specified options
  1. You should see all the properties. Scroll down to locate serverType property.
  2. Double click in the value field to select the serverType property. Click on the list box to set the property value as shown below:

Figure 11c. Select the serverType property
Select the property
  1. Select WEBSPHERE6.X from the list since we will be using WebSphere Application Server V6.1 Test environment to deploy this web service.

Figure 11d. Select WEBSPHERE6.X from the list
Select using WebSphere Application Server V6.1 Test environment
  1. Save the EGL build file by pressing CTRL+S or from menu File -> Save option.


Back to top


Code business logic

Next, create the service logic, which is supposed to run when somebody invokes this service.

To do this, create a file that contains the EGL logic, name this file, and place it into a package. You will use the New EGL Service Part wizard shown in Figure 12 to achieve this task.

  1. Expand the new Lab71Service project
  1. Right-click the EGLSource folder and select: New > Service

Figure 12. Project Explorer
menu command
  1. In the New EGL Service Part dialog shown in Figure 13,
    1. Enter the Package name: services.
    2. Enter the EGL source file name: zipService.
    3. Click the Finish button.

Figure 13. Set EGL service part options
specify folder, package, name, and interface

Next, create some logic in this source file to provide the functionality for this service. The service is very simple: it checks whether or not a ZIP code entry is a valid California ZIP code. Specifically, the logic checks that the input parameter value is between 90001 and 96000.

Add the source code shown in Listing 1 to zipService, which opened in the editor view.


Listing 1. Source to validate ZIP code
package services;

// service
service zipService

function caTestbk(zipIn char(5) in) returns(int)
if(zipIn >= "90001" && zipIn <= "96000")
return(0);
else
return(-1);
end
end
end
  1. Save and generate the service by pressing Ctrl+S, then Ctrl+G.


Back to top


Add service to an EGL file

To describe this service to the EGL environment, you need to add it to an EGL Deployment descriptor file, which has been created already during project creation.

  1. do the following in the Project Explorer, as shown in Figure 14.
    1. Expand the EGL Source directory.
    2. Locate the Lab71Service.egldd file (not the eglbld file, which is the build descriptor).
    3. Double-click the egldd file to open it in the editor.

Figure 14. Expand EGLSource in the Project Explorer
project files in tree view

You will notice that there are five tabs at the bottom of the EGL Deployment Descriptor Overview dialog shown in Figure 15.

  1. Click the Web Service Deployment tab.

Figure 15. Deployment Descriptor bindings, services, protocols, and imports
sections and tables in overview window
  1. Click Add in the window that displays.

Figure 16. List service parts to generate as Web services
table with Generate and Implementation columns
  1. In the Add Web Services dialog shown in Figure 17, select the zipService in the EGL service parts found list.
  2. Click ADD.

The service is moved to the EGL service parts to be generated as Web services list.

  1. Click Finish.
  2. Save and close the DeploymentDescriptor file.

Figure 17. Generate to Web services
found parts on left, parts to generate on right

The Deployment descriptor has been automatically added to the build file (.eglbd). This is necessary to make the Deployment descriptor known to the EGL build environment.

You might want to check the Build descriptor:

  1. In the EGL source directory, find the LAB71_Service.eglbld file.
  2. Double-click the file to open it with the source editor.

Note that the deployment descriptor Lab71Service is already listed under options, as shown in Figure 18.


Figure 18. Build options
Show only specified options
  1. Close the editor.

Re-generate the project so that EGL can take this new information and apply it to the generated application.

  1. Right-click the LAB7_Service project and click Generate, as shown in Figure 19.

Figure 19. Re-generate the project
menu command

The Generate action generates the complete Web service, including the WSDL file. The WSDL is a standard file format that describes a Web service. You can hand over this WSDL file to people that want to use your Web service. It describes the service interface, the location of the service, and other characteristics of the service.

The WSDL (commonly pronounced "Wis Dul") can be opened in the WSDL editor. The file is located in the project in WebContent\WEB-INF\wsdl\.

Figure 20 provides an example of how the WSDL editor presents your WSDL file.

  1. Double-click the WSDL file and look at it.

Figure 20. WSDL editor
diagram in editor

What you have done so far

You have now created an EGL Project and defined an EGL Web service. You have also added an entry in the deployment descriptor so that the service will be generated as a Web service.



Back to top



Go to the previous pagePage 3 of 9 Go to the next page