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. However, you can also selectively annotate the individual methods with @WebMethod annotation to control how these methods are exposed as Web services operations.
Using a combination of @WebService and @WebMethod annotations, you can easily describe your Web service because you control which methods are exposed.
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.
To define a class as an SEI-based Web Service, you must add the @WebService annotation to the implementation class. Providing a reference to an explicit SEI (interface) or a reference to an existing WSDL file in your service endpoint implementation class helps to remove possible ambiguities when exposing methods.
Beginning with Sun and HP JDK Version 1.6 containing JAX-WS tooling Version 2.1.6, the behavior of the JAX-WS runtime environment and tooling has changed how it interprets the JAX-WS specification regarding exposing methods as Web services operations. When the Web service does not specify a pre-existing WSDL file, the JAX-WS tooling behavior that generates a WSDL file has changed. This change does not affect Web services that reference a WSDL file. The change in semantics might affect Web services that do not reference a WSDL file or a SEI, and they rely on the JAX-WS runtime environment to create a WSDL file. Also, if you apply the best practices described previously in this document, the interpretation change does not affect your applications regardless of whether a WSDL file or SEI is referenced.
To prevent any security or migration exposures to existing WebSphere® Application Server applications, the JAX-WS runtime environment uses the legacy behavior so that new operations are not automatically exposed. For application server environments using both Version 7.0.0.7 and JAX-WS tooling Version 1.6, a new property is supported by the JAX-WS runtime environment. This new property specifies whether to use the legacy behavior, or the new behavior. By default, the JAX-WS runtime environment uses the legacy behavior for the @WebMethod annotation.
To specify that the JAX-WS runtime environment to use the legacy @WebMethod annotation behavior, configure the jaxws.runtime.legacyWebMethod=true property. You can configure this property as a Java Virtual Machine (JVM) system property. By default, this property is set to true and the application server uses the legacy behavior for the @WebMethod annotation.
To specify that the JAX-WS runtime environment to use the new @WebMethod annotation behavior, configure the jaxws.runtime.legacyWebMethod=false property. You can configure this property as a Java Virtual Machine (JVM) system property.
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.
You have used the @WebMethod annotation to specify which methods to expose as Web services operations.
If you have upgraded your application server environment to include Sun or HP JDK 1.6 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.
The following example illustrates the difference in behavior for the @WebMethod annotation based on the value of the jaxws.runtime.legacyWebMethod property for this sample service endpoint implementation file.
================================= public class Base { @WebMethod(exclude=false) public void superMethod1(String s) {...} public String superMethod2(String s) {...} ================================= @WebService(targetNamespace="foo") public class BeanImpl extends Base { @WebMethod(exclude=false) public void method1(String s) {...} public String method2(String s) {...} =================================
method1(String s) {...}
method1(String s) {...} method2(String s) {...} superMethod1(String s) {...}
Develop Java artifacts for JAX-WS applications from JavaBeans.
In this information ...Related tasks
Related reference
| IBM Redbooks, demos, education, and more(Index) |