Just like the service project, the client project uses
an EGL deployment descriptor file. However, in the client project,
the EGL deployment descriptor will hold information about where to
find services. You will import the WSDL file you created from the
service and EGL will add appropriate binding information to the EGL
deployment descriptor so the client can find the service.
In the process, EGL creates an interface part to represent
the service within the client project. Once the interface part is
bound to the actual service, you can use that interface part as though
it were the service itself.
Use the service in the web page
- Open the JSF Handler for the web page, named ClientPage.egl.
- In the JSF Handler, create a variable from the interface
part. It is usually easiest to use content assist to create a variable
in this way:
- In the JSF Handler file, place the cursor on a blank
line immediately after the three variables you created in a previous
section.
- On the blank line, type the following code, as the first
few characters of the interface part:
he
- Press CTRL+space. The content assist
completes the line for you with the following code:
helloService HelloService {@bindService};
Content
assist also adds an import statement to the
JSF Handler so you can use this part without specifying its complete
location. The results look like the following picture:
- On a blank line within the getHello() function,
invoke the SayHello() function in the service by
passing it the name and city variables
and assigning the output to the output variable:
output = helloService.SayHello(name, city);
Remember
that you can use content assist by typing the first few characters
of a keyword or part and then pressing CTRL+space. The
JSF Handler looks like this:
- Save and close the JSF Handler.
- Generate the entire client project by right-clicking it
in the Project Explorer view and then clicking Generate.
- Next, for testing purposes, you must let your application
server know about the service you intend to call. In the Servers view,
right-click the appropriate version of WebSphere Application
Server and click Add and Remove Projects.
- On the Add and Remove Projects page, verify that both the
EGLClientEAR and the EGLServiceEAR are listed as Configured
projects. If the EGLServiceEAR is in the Available
projects column, click it to highlight it, then click Add and Finish. The window looks like the following picture:Now the web page is ready to use.
- In the Project Explorer view, right-click the ClientPage.jsp web
page in the WebContent folder, not the JSF Handler, and then click .
- In the Define a New Server window, click the radio button
for Choose an existing server, then click the
appropriate version of WebSphere Application Server.
Click Finish. The server publishes
the page and displays it in the internal web browser. If you prefer
to use an external web browser, you can copy the URL from the internal
web browser and paste it into the URL field of the external web browser.
- Type a name and city into the name and city fields, and
then press the button on the page. The output field
on the page shows a string such as "Bill, welcome to New York!" depending
on the name and city you enter, as in this picture:
This may seem like a lot of work for a simple task, but these
projects demonstrate how EGL can create services, clients, or both,
and how those applications work together. Using web services and clients
in service-oriented architecture, you can integrate a wide variety
of EGL and non-EGL applications in a way that is flexible and modular.