Example of a JWS File

Programming the JWS File 4-3

4.3.1 Example of a JWS File

The following sample JWS file shows how to implement a simple Web service. package examples.webservices.simple; Import the standard JWS annotation interfaces import javax.jws.WebMethod; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; Table 4–1 Steps to Program the JWS File Step Description 1 Import the standard JWS annotations that will be used in your JWS file. The standard JWS annotations are in either the javax.jws, javax.jws.soap , or javax.xml.ws package. For example: import javax.jws.WebMethod; import javax.jws.WebService; import javax.jws.soap.SOAPBinding; import javax.xml.ws.BindingType; 2 Import additional annotations, as required. For a complete list of JWS annotations that are supported, see Web Service Annotation Support in WebLogic Web Services Reference for Oracle WebLogic Server. 3 Add the standard required WebService JWS annotation at the class level to specify that the Java class exposes a Web service. See Section 4.3.2, Specifying that the JWS File Implements a Web Service WebService Annotation. 4 Add the standard SOAPBinding JWS annotation at the class level to specify the mapping between the Web service and the SOAP message protocol. Optional In particular, use this annotation to specify whether the Web service is document-literal, document-encoded, and so on. See Section 4.3.3, Specifying the Mapping of the Web Service to the SOAP Message Protocol SOAPBinding Annotation. Although this JWS annotation is not required, Oracle recommends you explicitly specify it in your JWS file to clarify the type of SOAP bindings a client application uses to invoke the Web service. 5 Add the JAX-WS BindingType JWS annotation at the class level to specify the binding type to use for a Web service endpoint implementation class. Optional See Section 4.3.7, Specifying the Binding to Use for an Endpoint BindingType Annotation. 6 Add the standard WebMethod annotation for each method in the JWS file that you want to expose as a public operation. Optional Optionally specify that the operation takes only input parameters but does not return any value by using the standard Oneway annotation. See Section 4.3.4, Specifying That a JWS Method Be Exposed as a Public Operation WebMethod and OneWay Annotations. 7 Add WebParam annotation to customize the name of the input parameters of the exposed operations. Optional See Section 4.3.5, Customizing the Mapping Between Operation Parameters and WSDL Elements WebParam Annotation. 8 Add WebResult annotations to customize the name and behavior of the return value of the exposed operations. Optional See Section 4.3.6, Customizing the Mapping Between the Operation Return Value and a WSDL Element WebResult Annotation. 9 Add your business code. Add your business code to the methods to make the WebService behave as required. 4-4 Getting Started With JAX-WS Web Services for Oracle WebLogic Server Standard JWS annotation that specifies that the porType name of the Web Service is SimplePortType, the service name is SimpleService, and the targetNamespace used in the generated WSDL is http:example.org WebServicename=SimplePortType, serviceName=SimpleService, targetNamespace=http:example.org Standard JWS annotation that specifies the mapping of the service onto the SOAP message protocol. In particular, it specifies that the SOAP messages are document-literal-wrapped. SOAPBindingstyle=SOAPBinding.Style.DOCUMENT, use=SOAPBinding.Use.LITERAL, parameterStyle=SOAPBinding.ParameterStyle.WRAPPED This JWS file forms the basis of simple Java-class implemented WebLogic Web Service with a single operation: sayHello public class SimpleImpl { Standard JWS annotation that specifies that the method should be exposed as a public operation. Because the annotation does not include the member-value operationName, the public name of the operation is the same as the method name: sayHello. WebMethod public String sayHelloString message { System.out.printlnsayHello: + message; return Here is the message: + message + ; } }

4.3.2 Specifying that the JWS File Implements a Web Service WebService Annotation