Annotating a Java bean to create a Web service

You can annotate types, methods, fields, and parameters in your Java™ bean to specify a Web service.

Prerequisites:

To annotate your Java bean:

  1. In the Enterprise Explorer view, double-click your Java bean to open the file in the Java editor.

  2. 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.

  3. 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 below 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.

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. You can also generate deployment descriptors and manage the policy sets associated with the service from this view.

For detailed information about these and other annotations, see the related reference.

For information about validation of Web services annotations, see the related concept:

 

Related tasks

Creating a JAX-WS enabled dynamic Web project

 

Related reference

JAX-WS annotations reference

Rules for methods in classes annotated with @WebService