Generating a JAX-WS Web Service Client
See Also
A web service can be consumed in a web application, a Java application, or
a MIDP client (MIDlet). For information on consuming web services
in a MIDlet, see the Java ME Mobility documentation.
For JAX-WS clients, all imported WSDL files and schemas are
resolved automatically by the IDE. For JAX-RPC clients,
before you begin, note that if the WSDL file that you want to use imports schemas, other WSDL files, or both, from the local file system, the web service client will only work
if the imported schemas and WSDL files are copied beforehand into the WEB-INF/wsdl (or META-INF/wsdl)
folder. If you do not do this,
the wscompile tool
will not be able to locate these imported files at the end of the procedure below.
To create a web service client:
- Create the project to contain the web service client. Depending on how you want to
consume the web service, create a web application project or a Java application project.
- From the Projects window or Files window, right-click a node
in the project and choose New > Other.
The New File wizard appears. Under Categories, select Web Services. Under File Types, select Web Service Client.
Click Next.
- Access the WSDL file of the web service that the web service client is to consume.
Depending on what the provider has distributed, do the following:
- To generate a client from a project
on your local filesystem, click Project and browse to a project's
web service port icon.
- To generate a client from a WSDL file
on your local filesystem, click Local File and browse to the WSDL file on
your local filesystem.
- To generate a client from a running web service, click WSDL URL,
then type or paste the web service's URL.
If you are behind a corporate firewall, click Proxy Settings and
set your proxy host and port number.
- The WSDL file is downloaded when you finish the wizard.
- Optionally, specify the package where the client files will be generated. When you complete
the wizard, you can find the generated client files in the Projects window, in the Generated
Sources node of the client project, or in the Files window, within the
build folder.
If you do not specify a package name, the IDE generates the client
files in the default package, which is based on the namespace in the WSDL. You can change this package name later in the
WSDL Customization editor.
- Specify whether to use JAX-WS or the older JAX-RPC client style. JAX-WS is selected
by default. However, older services may require JAX-RPC clients. Install the JAX-RPC Web Services plugin to create JAX-RPC clients.
If you are creating a client in a J2EE 1.4 web application, the RPC style is automatically selected,
and additional options for Client Type appear. See JAX-RPC Clients in J2EE 1.4 Web Applications.
- If you want to use raw XML messages when invoking the web service, select Generate Dispatch Code. The client code is generated using the java.xml.ws.Dispatch interface instead of the usual service endpoint interface. This is an advanced feaure and is unselected by default.
- Click Finish.
JAX-RPC Clients in J2EE 1.4 Web Applications
If you are creating a web service client in a J2EE 1.4 web application, a Client Type drop-down list appears with the following
options:
- J2EE Container-generated static stub.
This type is based on JSR-109, which enhances JSR-101 by defining the packaging
of web services into standard J2EE modules, including a new deployment descriptor,
and defining web services that are implemented as session beans or servlets.
This is the recommended and portable (via J2EE 1.4 specification) type.
When you choose this type, the IDE adds deployment information in the
deployment descriptors and the container generates the stub and other artifacts.
- IDE-generated static stub.
This type is based on JSR-101, which defines the mapping of WSDL to Java and vice versa.
It also defines a client API to invoke a remote web service and a runtime environment
on the server to host a web service. This type is not portable.
When you choose this type, the IDE generates
the stub and other
artifacts, packages them in the archive, and deploys them.
- See Also
- About Web Service Clients
- About Web Services
Legal Notices