< Previous | Next >

Lesson 4: Set up the project as a client

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.

Set up the EGL deployment descriptor file

  1. Open the client project's EGL deployment descriptor file by double-clicking EGLClient/EGLSource/EGLClient.egldd in the Project Explorer view. Note that the EGL deployment descriptor has no relation to the Java™ Deployment Descriptor folder, which is also in the EGLClient project.
  2. In the deployment descriptor editor, go to the Service Bindings tab.
  3. On the Service Bindings tab, click Add.
  4. In the Add a Service Binding window, click SOAP service binding.
  5. Click Next.
  6. Select the Choose wsdl file from workspace and copy it to the current project check box.
  7. Click Browse.
  8. Select the HelloService.wsdl file, which is located in the EGLService project in the folder EGLSource\wsdl, and then click OK.
  9. Under Interface Options, select the Generate EGL Interface from WSDL file radio button. With this option selected, EGL will create the parts you need to access the service automatically.
  10. Accept the defaults for the other fields on the page and click Next. The New EGL Interface page shows a list of all the services described in the WSDL file. EGL will create an interface part in the client project for each service you select on this page. For now, only the service you created in the service project is listed here.
  11. Make sure the check box for the HelloService service is selected and then click Next. The next page allows you to set where the new interface part will be created and what it will be named. You can also select which functions from the service to include in the interface part. By default, all of the functions in the service part are included.
  12. In the Source folder field, make sure that the client project's source folder is specified: EGLClient\EGLSource.
  13. In the Package field, make sure that the services package is specified.
  14. Make sure that the check box next to the SayHello function is selected in the Functions list.
  15. Click Finish. You have now created a service binding. Using this binding, the web page you created in this project can access the service. The binding in the deployment descriptor file looks like this:
    The client's deployment descriptor file
  16. Save and close the deployment descriptor file. Note that EGL has created an interface part in the project's services package. The interface part looks like this:
    The new interface part

    This interface is similar to the one you created in the service application, but this one has additional properties to refer to the binding in the deployment descriptor file.

  17. Just as you did in the EGLService project, make sure the deployment descriptor appears in the client build descriptor file:
    1. Double-click the build descriptor for the project to open it in the build parts editor. This file is named EGLClient.eglbld and is located in the project's EGLSource folder.
    2. In the list of build descriptor options, the option named deploymentDescriptor should be set to EGLClient.
    3. Click OK and close the file.

Use the service in the web page

  1. Open the JSF Handler for the web page, named ClientPage.egl.
  2. 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:
    1. In the JSF Handler file, place the cursor on a blank line immediately after the three variables you created in a previous section.
    2. On the blank line, type the following code, as the first few characters of the interface part:
      he	
    3. 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:
      The content assist completes the line
  3. 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:
    The code in the JSF Handler
  4. Save and close the JSF Handler.
  5. Generate the entire client project by right-clicking it in the Project Explorer view and then clicking Generate.
  6. 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.
  7. 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:
    The completed Add and Remove Projects window shows EGLServiceEAR as configured on the server
    Now the web page is ready to use.
  8. In the Project Explorer view, right-click the ClientPage.jsp web page in the WebContent folder, not the JSF Handler, and then click Run As > Run on Server.
  9. 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.
  10. 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:
    The finished page
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.
< Previous | Next >

Feedback