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:
- Your workspace contains a Java bean that has at least one public method.
- This Java bean is in a dynamic Web project or basic Java project.
To annotate your Java bean:
- 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 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:
- Creating a Web service from an annotated Java bean by using a wizard
After annotating a Java bean, you can generate a Web service application by using the Web services wizard. With the wizard, you can create a WSDL file in your Web services project before you deploy the application to a server.- Creating a Web service from an annotated Java bean by publishing to a server
After annotating a Java bean, you can generate a Web service application by publishing the application project of the bean directly to a server. When your Web service is generated, no WSDL file is created in your project.
Related tasks
Creating a JAX-WS enabled dynamic Web project
Related reference
Rules for methods in classes annotated with @WebService