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
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
or javax.jws.soap package. For example: import javax.jws.WebMethod;
import javax.jws.WebService; import javax.jws.soap.SOAPBinding;
2 Import the WebLogic-specific
annotations used in your JWS file.
The WebLogic-specific annotations are in the weblogic.jws
package. For example: import weblogic.jws.WLHttpTransport;
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, RPC-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 WebLogic-specific
WLHttpTransport JWS
annotation at the class level to specify the context path and
service URI used in the URL that invokes the Web service.
Optional See
Section 4.3.4, Specifying the Context Path and Service URI of the Web Service WLHttpTransport
Annotation. Although this JWS annotation is not required, Oracle
recommends you explicitly specify it in your JWS file so that it is clear what URL a client application uses to
invoke the Web service.
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.5, 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.6, 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.7, 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-RPC Web Services for Oracle WebLogic Server
import javax.jws.WebMethod; import javax.jws.WebService;
import javax.jws.soap.SOAPBinding; Import the WebLogic-specific JWS annotation interfaces
import weblogic.jws.WLHttpTransport; 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
WebLogic-specific JWS annotation that specifies the context path and service URI used to build the URI of the Web Service is
simpleSimpleService WLHttpTransportcontextPath=simple, serviceUri=SimpleService,
portName=SimpleServicePort 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