You can use the @WebService and @WebMethod annotations on a service endpoint implementation to specify Java methods that you want to expose as Java API for XML-Based Web Services (JAX-WS) web services.
JAX-WS technology enables the implementation of web services based on both the standard service endpoint interface and a Provider interface. When developing a JAX-WS web service starting from existing Java classes, known as the bottom-up approach, you must annotate the class with either the @WebService or @WebServiceProvider annotation to initially define the class as a web service.
Using the Provider interface is the dynamic approach to defining your JAX-WS services. To use the Provider interface, your class must implement the javax.xml.ws.Provider interface, and contain the @WebServiceProvider annotation. The Provider interface has one method, the invoke method, which uses generics in the Java programming language to control both the input and output types when working with various messages or message payloads.
In contrast, this topic describes how you can use Java annotations to describe your web services using the service endpoint interface (SEI) approach.
To initially define a web service, annotate the Java class with the @WebService annotation. You can also selectively annotate individual methods with the @WebMethod annotation to control their exposure as web services operations.
Because of ambiguities across multiple web services specifications regarding how methods are exposed as operations, use the following guidelines to help ensure consistent behavior regardless of the JAX-WS implementation that you use.
The behavior of JAX-WS has changed regarding exposing methods as web services operations. This complies with recent clarifications to JAX-WS specifications.
Applications without an explicit SEI or WSDL that are migrated from prior versions might have additional operations exposed as shown below. You can set a property so the JAX-WS runtime environment uses the legacy behavior. You might need this when migrating applications without a WSDL or an SEI so that additional methods are not exposed.
@WebService public class Foo { @WebMethod public void a() {} // exposed now, exposed before public void b() {} // exposed now, not exposed before }
To specify that the JAX-WS runtime environment use the legacy @WebMethod behavior, configure the jaxws.runtime.legacyWebMethod=true property. You can configure this property as a Java Virtual Machine (JVM) system property or as a property in the META-INF/MANIFEST.MF file of a web application archive (WAR) file. By default, this property is set to false and the application server uses the new behavior.
javax.xml.ws.WebServiceException: WSWS7054E: The Web Services Description Language (WSDL) file could not be generated for the XXXX Web service implementation class because of the following error: javax.xml.ws.WebServiceException: Unable to create JAXBContextThe JAX-WS tooling complies with the JAX-WS specification with respect to @WebMethod mapping principles. This change might affect applications that have been dependent on previously non-compliant default behavior. If your applications package and reference WSDL or an SEI and have ALL methods correctly annotated with the @WebMethod exclude flag in the SEI implementation, then this change does not affect you. However, if you are affected, add explicit annotations to your methods to ensure that they are excluded in WSDL generation. For example: @WebMethod(exclude=true) Also, you can package a WSDL with your application to eliminate the need for the run time to generate a WSDL on your behalf.
Static or final methods in a service without an explicit SEI are no longer exposed as web services operations. To expose them, package the WSDL with the application and set jaxws.runtime.legacyWebMethod=true.
You have used the @WebMethod annotation to specify which methods to expose as web services operations.
If you have upgraded your application server environment and you are experiencing problems, review the following troubleshooting information.
javax.xml.ws.WebServiceException: The Endpoint validation failed to validate due to the following errors: :: Invalid Endpoint Interface :: :: The number of operations in the WSDL portType does not match the number of methods in the SEI or web service implementation class. wsdl operations = [...] dispatch operations = [....]
To correct this problem, you must regenerate client artifacts to match the WSDL file.
The endpoint reference (EPR) for the Operation not found is http://localhost:9086/example/BeanImpl2Service and the WSA Action = <WSA_action_from_server>. If this EPR was previously reachable, contact the server administrator.
Develop Java artifacts for JAX-WS applications from JavaBeans.
In this information ...Related tasks
Related reference
| IBM Redbooks, demos, education, and more(Index) |