< Previous | Next >

Lesson 3: Creating the web service client

In this lesson you will learn how to create a client for the web service.

Before you begin

Before you begin, you must complete Lesson 2: Creating the web service.

About this task

Web service clients are created from a WSDL document that describes where the web service is deployed and what operations this service provides. You can use either the static WSDL file generated by the web service wizard, or when creating JAX-WS web services you can use the dynamic WSDL file generated by the runtime based on information it gathers from the annotations added to the Java classes. For this tutorial the dynamic WSDL file will be used.

View the dynamically generated WSDL

About this task

If your server is started you should be able to quickly test your annotated bean to ensure it is a web service and generate the dynamic WSDL file.

Procedure

  1. Determine the port your web service is using if you do not already know it. To do this:
    1. Launch the WebSphere Application Server Administrative Console by right-clicking your server in the Servers view and selecting Administration > Run administrative console.
    2. Expand Servers > Server Types, and select WebSphere application servers.
    3. Select your server name from the list. By default this is server1.
    4. On the Configuration tab, search for the Communications heading and expand Ports.
    5. The port used is WC_defaulthost. This tutorial will use the example port number 9081. Replace this number with your own port in any following steps.
  2. Launch the Web browser by clicking this icon: Web browser icon as it appears in the main toolbar
  3. Enter the following URL in the browser: http://localhost:9081/jwsAddressBook/AddressBookService and hit return. A page displays stating that this is a web service.
  4. Add ?wsdl to the end of the URL in step 3 and hit return again: http://localhost:9081/jwsAddressBook/AddressBookService?wsdl. The dynamically generated WSDL file will be displayed. This file can be used the same way as you would use the static WSDL file that the web service wizard generated as long as the server is running.

Create the address book web service client and test JSP

Procedure

  1. Click File > New > Other. Select Web Services in order to display the various web service wizards. Select the Web Service Client wizard. Click Next.
  2. Web Services page: Enter the URL of the dynamically generated WSDL file that you discovered in the previous section in the Service definition field: http://localhost:9081/jwsAddressBook/AddressBookService?wsdl.
    1. Select the stages of web service client development that you want to complete using the slider. For this tutorial select Test client. This will generate all the required client code and provide various testing options for the client.
    2. Server: Ensure the WebSphere v7.0 and up server is selected.
    3. Web service runtime: Ensure the JAX-WS runtime is selected.
    4. Client project: Select the client project created in lesson 1: jwsAddressBookClient.
    5. Client EAR project: Select the jwsAddressBookEAR. For JAX-WS web services, the server and client projects can share the same EAR.
    6. Monitor the web service: This will send the web service traffic through the TCP/IP Monitor, which allows you to watch the SOAP traffic generated by the web service and to test this traffic for WS-I compliance. The TCP/IP Monitor is not capable of monitoring web services secured with the RSP policy set, so do not select this option..
    Click Next.
  3. WebSphere JAX-WS Web Service Client Configuration page:
    • Output folder: Accept the default folder where the client's Java classes will be generated.
    • Target package: The web services client wizard generates a number of Java files from the specified WSDL. By default it will create a package name based on the namespace specified in the WSDL file. To override this default behavior you can specify your own package name for the namespace in the WSDL file. Accept the defaults for this tutorial.
    • Generate portable client: Selecting this checkbox would allow you to move your web service client code from one machine to another or from one instance of WebSphere Application Server to another. It is not required by this tutorial.
    • Enable asynchronous invocation for generated client: If you select to enable an asynchronous client, for each method in the web service two additional methods will be created. These are polling and callback methods which allow the client to function asynchronously. Select this option.
    • Specify JAX-WS or JAXB binding files: If you have created JAX-WS or JAXB custom binding files, select this check box to use them to create this web service. Do not select this for the tutorial.
    • Customize client proxy class name: You can accept the default proxy name or enter your own. Do not select this for the tutorial.
    • Generate schema library: Selecting this will run the JAX-WS Schema to Java compiler to generate a schema. Do not select this option for this tutorial.
    • Generate web service deployment descriptor: For JAX-WS web services deployment information is generated dynamically by the runtime; static deployment descriptors are no longer required. Selecting this checkbox will generate them. This tutorial does not require deployment descriptors.
    • Version of JAX-WS code to be generated: Starting with WebSphere Application Server v7.0, you can generate JAX-WS 2.1 compliant code. Select 2.1 for this tutorial.
    Click Next.
  4. Web Service Client Test page:
    • Test the generated proxy: Select this to test the functionality of the client.
    • Select your test facility. You can test the generated proxy in the Universal Test Client or the Web Service Explorer, or you can generate sample JAX-WS 2.0 JSPs. For this tutorial, select the JAX-WS JSPs.
    • Folder: You can select the folder where the JSP will be located. Accept the default.
    • Methods: Select the methods to expose. The asynchronous methods should be listed as well. Ensure all methods are selected.
    • Run test on server: this will start the server for you automatically.
    Click Finish. The sample JSP will open in a browser window.

Test the web service client using sample JSPs

About this task

The following steps will test the web service synchronously .

Procedure

  1. The TestClient.jsp should be launched automatically if you selected the correct options. If it is not displayed, select jwsAddressBookClient/WebContent/sampleAddressBookPortProxy/TestClient.jsp, right-click and select Run As > Run on Server
  2. To test the service synchronously, select the saveAddress method and enter information in the name field. All other fields are optional. Click Invoke.
  3. Select the findAddress method, enter the name you used during the saveAddress method, and click Invoke. The information saved by the saveAddress method should display in the results pane.
  4. To test the service asynchronously, in the Quality of Service pane select the Enable asynchronous invocation checkbox.
  5. Select the findAddress method, enter the name you used during the saveAddress method, and click Invoke.
  6. A new link will display indicating that the method is in progress. Click the link to display the method response in the Results pane.

Results

Once you have tested the web service leave the JSP open so that you can test the service again once the web service and client have been secured.

Lesson Checkpoint

< Previous | Next >
Icon that indicates the type of topic Tutorial lesson topic
Timestamp icon Last updated: July 17, 2017 21:58

File name: jaxwstd_exercise13.html