Annotating an EJB bean to create a Web service

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

Prerequisites:

The steps for creating a Web service from an EJB bean using annotations is as follows:

  1. Annotate your EJB bean with the @WebService and @Stateless annotations, and any other annotations required for your implementation.

  2. Create JMS or HTTP router modules for the Web service as described in: Creating Web service router modules

  3. Publish the application to a server as described in: Creating a Web service from an annotated EJB bean by publishing to a server
To annotate your EJB 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 and @Stateless annotations. 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.

 

Related reference

JAX-WS annotations reference