Top
Interstage Studio User's Guide
FUJITSU Software

D.3.5 Creating a Web Service Client

This section explains the procedure for creating a Web service client application.

Point

Add the required libraries using the following procedure to create Web service clients:

  1. Select the project. From the context menu, click [Properties] > [Java Build Path] > [Libraries] tab > [Add Library...] and in [Server Runtime] specify [Interstage Application Server V11.1 IJServer (J2EE)] and click [Finish].

  2. Next, add the following JAR files in [Add External JARs]:
    <product installation folder>\APS\J2EE\lib\isws-saaj-api.jar

  3. In the [Order and Export] tab, move the JAR files that were added in 2 above [JRE System Library] then click [OK].

Acquiring Web service interface information (WSDL files)

WSDL files are required for creating a Web service client.

When creating an Interstage Application Server Web service, from the tree on the left side of the Interstage Management Console, click [Web Service] > [Web Service Class Name]. On the [Web Service] page, select the [General] tab. The WSDL file URL can be obtained from [WSDL] on the [Web Service] page.

If Web service development resources already exist, you can also use the WSDL files of the development resources.

Point

Location information (URL of the Web service) as defined in a WSDL file will be output to files that are created from the WSDL file. To change the runtime environment, you can change the connection destination by customizing the environment setting without rebuilding the application. However, it is easier to use the WSDL file that contains location information for the Web service to be used.

Publicly available WSDL files that can be acquired through Interstage Management Console contain location information that is updated to reflect the environment at the deployment destination. By using these files, you need not consider the connection destination.

If you are also developing a Web service application at the same time, however, you can use the WSDL files of development resources as is, without having to perform deployment or other such work, by specifying debugging environment location information in the Web Service wizard in advance. Web service applications and Web service clients can thereby be developed in parallel.

If the Web Service Client is a J2EE application and JNDI lookup is used to acquire the service interface, you do not need to know the location information that is described in the WSDL file.

Generating a stub

You can create a Java class required for access to a Web service, from the WSDL file that defines a Web service interface. From [New] wizard, select [Web Services] > [IJServer] > [Web Service Client (JAX-RPC)] and use the wizard to generate a stub. See below for the wizard settings.

Note

Before you can use the Web Service Client(JAX-RPC) wizard, the Interstage Application Server function or Interstage Application Server client package must be installed.

The table below lists files created by the Web Service Client(JAX-RPC) wizard.

Created file

File name

Description

Service endpoint interface

<WSDL portType-name>.java

Contains a description of the Java interface that represents the Web service endpoint interface to be used.

Service interface

<WSDL service-name>.java

Contains a description of the interface used to acquire the stub defining the Web service endpoint in a Web service.

User-defined-type class

xxxxx.java

Created only for a Web service that uses user-specific types.

Holder class

xxxxxHolder.java

Created only if standard Holder classes do not exist, as in a case with a user-defined type or array.

Other class

_isws_+XXXXX+.java

Class required for running a Web service client. Your application need not consider whether this class is used.

Point

For the rules regarding conversion from an XML type for WSDL to the Java type used during file creation, refer to the "Interstage Application Server J2EE User's Guide".

Note

If you are also creating a Web service application, the service endpoint interface created for the Web service application may be different from the service endpoint interface created from the WSDL file for a Web service client. Therefore, when developing a Web service client, use the service endpoint interface generated from the WSDL file.

Developing a Web service client

Create a client application that uses the generated stub to access the Web service.

The client application gets the stub and invokes the stub method to access the Web service.

The following methods describe how to acquire stubs.

Acquiring stubs when JNDI was used to lookup the Service object

If invoking a Web service from a Web application, an EJB Application or a J2EE application client, it is possible to perform lookup of the service object using JNDI.

Editing the deployment descriptor

If using JNDI to lookup the service object from the Web Service client application, depending on the mode of the client application, the service reference description must be defined in the deployment descriptor shown below.

Client Application Mode

deployment descriptor

Web Application

web.xml

EJB Application

ejb-jar.xml

J2EE Application client

application-client.xml

Accessing Web Service from stubs by acquiring a service object

  1. Create an InitialContext object
    Create a new InitialContext object.

  2. Acquire a Service object
    Use the lookup method of the acquired InitialContext object to acquire a service object.
    In the argument of the lookup, specify the following character string.
    java:comp/env/[ value specified in <service-ref-name> of the deployment descriptor]

  3. Acquire the stub object
    Use the method of the acquired service object to acquire the stub object (an instance of the class that implements the service endpoint interface).

  4. Invoke the stub object method
    Invoke the method of the acquired stub object to access the Web service.

Note

If JNDI is used to perform lookup of a service object, it is not possible to use a single InitialContext object with multiple threads.

Point

If using JNDI from a J2EE application client, the environment of the JNDI service provider must be configured. For details on the JNDI service provider environment settings, refer to the "Interstage Application Server J2EE User's Guide".

Acquiring stubs using ServiceFactory

  1. Acquiring the ServiceFactory object
    Invoke the newInstance method of the javax.xml.rpc.ServiceFactory class provided by JAX-RPC to acquire the ServiceFactory object.

  2. Acquiring the Service object
    Use the loadService (java.lang.Class) method of the acquired ServiceFactory object to acquire a Service object (an instance of the class that implements the service interface).

  3. Acquiring a stub object
    Use the method of the acquired Service object to acquire a stub object (an instance of the class that implements the service endpoint interface).

  4. Invoking the stub object method
    Call the method of the acquired stub object to access the Web service.

For details on the methods used, refer to the "Interstage Application Server J2EE User's Guide" and javadoc documents about Web services.