You can annotate types, methods, fields, and parameters
in your Java™ bean to specify
a web service.
Before you begin
Prerequisites:
- Your workspace contains a Java bean
that has at least one public method.
- This Java bean is in a web
project or basic Java project.
About this task
To annotate your Java bean:
Procedure
-
In the Enterprise Explorer view, double-click your Java bean to open the file in the Java editor.
-
On the Java class
that implements your web service, specify the @WebService annotation.
Also specify the attributes, if any, that you want the annotation
to have.
- Most errors that display when adding annotations can be resolved
using the suggested quickfixes. To display the quickfixes, click the
error marker.
- To add annotations or attributes to existing annotations, you
can use the Annotations view rather than manually adding this information
to the class. This view provides basic validation and guidance when
working with annotations.
-
Optional: Use these and other annotations to customize
your web service further:
- On the Java class that
implements your web service, specify the @WebMethod annotation on
each method that you want to customize for the service. You can use
this annotation to exclude a method from your service. By default,
all public methods are exposed in a service, including inherited methods
that are under the Object class.
- On the methods that are exposed in your web service, use the
@WebParam and @WebResult annotations to customizes the mapping of
your parameters and results to message parts and XML elements.
- On an exception class, specify the @WebFault annotation to
map your class to a WSDL fault.
Results
Once the annotations have been added to the bean, the Services
view should list the web service under the JAX-WS heading. From this
view you can test the web service by right-clicking it and selecting Test
with Web Services Explorer or Test with Generic
Service Client. You can also generate deployment descriptors
and manage the policy sets associated with the service from this view.