Skip Headers
Oracle® Application Server Web Services Developer's Guide
10g Release 3 (10.1.3)
B14434-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

5 Assembling a Web Service from a WSDL

This chapter describes how to assemble a Web service, starting with a Web Service Description Language (WSDL) file. This is also known as top down Web service generation.

What Is Top Down Assembly?

In top down Web service assembly, you generate a service from an existing WSDL file that models the business processes you want to expose.

A development tool, such as WebServiceAssembler, uses the WSDL to generate the service endpoint interface for the service. You can then implement the service for any supported architecture, such as Java classes. After compiling the implementation, you generate the service and deploy it to the application server.

Chapter 4, "Oracle Application Server Web Services Messages" provides information about the message formats you can assign to a Web service.

How to Assemble a Web Service Top Down

This section describes what you must provide to assemble a Web service top down. Assembling a Web service requires the WebServiceAssembler tool, and Java platform tools such as the javac compiler, that are found in the J2SE 1.4 SDK distribution.

There are three general steps for generating a Web service top down:

  1. Generate the service endpoint interface.

    WebServicesAssembler can perform this step.

  2. Implement and compile the services.

    The developer performs this step.

  3. Assemble the services.

    WebServicesAssembler can perform this step. "Generating the Web Service Top Down" provides more detail on each of these steps.

Prerequisites

Generating a Web service top down with WebServiceAssembler requires you to specify only the WSDL and an output directory.

Before you generate Web services, consider these issues:

  • WebServicesAssembler places some restrictions on the WSDL that you specify:

    • The WSDL should comply with Web Services-Interoperability (WS-I) Basic Profile 1.0. If it does not, WebServiceAssembler provides command-line arguments that enable you to work around many limitations in the WSDL. Chapter 17, "Using WebServicesAssembler" provides descriptions of WebServicesAssembler commands and arguments.

    • Only one service element can be implemented. WebServicesAssembler enables you to generate the artifacts for only one service at a time. If more than one service is described in the WSDL, a command line argument, serviceName, enables you to specify the service you want to use.

    • The message format is specified in the WSDL. You cannot use WebServicesAssembler to change the message format in top down Web service development.

    • The WSDL cannot contain multiple message formats. Remove any ports from the WSDL that reference a binding with a message format that you do not want to use.

Generating the Web Service Top Down

The following steps illustrate how to assemble a Web service top down. The Web service will provide a logging facility that is defined by the WSDL stored at wsdl/LoggingFacility.wsdl.

  1. Provide a WSDL from which the Web service will be generated as input to the WebServiceAssembler genInterface command. For example:

    java -jar wsa.jar -genInterface 
                      -output build/src/service  
                      -wsdl wsdl/LoggingFacility.wsdl 
                      -unwrapParameters false 
                      -packageName oracle.demo.topdowndoclit.service 
                      -mappingFileName type-mapping.xml
    
    

    At a minimum, specify the name of the WSDL. For more information on the required and optional arguments to genInterface, see "genInterface".

    The WebServiceAssembler tool generates a Java interface for every port type specified in the WSDL, and a Java Bean for each complex type. The name of the directory that stores the generated interface is based on the values of the output and packageName arguments. For this example, the generated interface is stored in build/src/service/oracle/demo/topdowndoclit/service. The value types are stored in the specified output directory, but the package name is based on the type namespace or values in the JAX-RPC mapping file, type-mapping.xml.

  2. Compile the generated interface and type classes. For example:

    javac build/src/service/*.java -destdir build/classes 
    
    
  3. Create the service endpoint implementation for your Web service.

    The Java service endpoint must have a method signature that matches every method in the generated Java interface.

  4. Compile the Java service endpoint.

    For example, you can use the same command as in Step 2 if the Java service endpoint interface source was generated in the same directory where the Impl class was saved. If it was not, then you must change the value of the path argument.

  5. Assemble the service by running the WebServiceAssembler tool with the topDownAssemble command. For example:

    java -jar wsa.jar -topDownAssemble 
                -wsdl ./wsdl/LoggingFacility.wsdl 
                -unwrapParameters false 
                -className oracle.demo.topdowndoclit.service.DocLitLoggerImpl 
                -input build/classes/service 
                -output build 
                -ear dist/doclit_topdown.ear 
                -mappingFileName type-mapping.xml 
                -packageName oracle.demo.topdowndoclit.service 
                -fetchWsdlImports true 
                -classPath ./build/classes/client 
    
    

    At a minimum, specify the name of the WSDL, the class name that implements the service, and the name of the output directory. The WebServiceAssembler tool outputs an EAR file, and a WAR file within the EAR. The WAR file contains the service artifacts, the implementation classes, the Web deployment descriptor (web.xml) and the JAX-RPC deployment descriptor (webservices.xml). For more information on the required and optional arguments to topDownAssemble, see "topDownAssemble".

  6. Deploy the service.

    Deploy the EAR file in the standard manner into a running instance of OC4J. For more information on deploying EAR files, see the Oracle Containers for J2EE Deployment Guide. The following is a sample deployment command.

    java -jar <oc4jHome>/j2ee/home/admin_client.jar deployer:oc4j:localhost:port <user> <password> 
                -deploy 
                -file dist/doclit_topdown.ear 
                -deploymentName doclit_topdown 
                -bindWebApp default-web-site
    
    

    The following list describes the parameters in this code example:

    • <oc4j_Home>—the directory containing the OC4J installation.

    • <user>—the user name for the OC4J instance. The user name is assigned at installation time.

    • <password>—the password for the OC4J instance. The password is assigned at installation time.

    • doclit_topdown—the name of the application.

    • default-web-site—the Web site to which the application will be bound. This is usually default-web-site. To configure Web sites, see the server.xml file in <oc4j_home>/j2ee/home/config.

  7. (Optional) Check that deployment succeeded. OracleAS Web Services provides a Web Service Home Page for each deployed Web service. See "Using the Web Services Home Page" for information on accessing and using the Web Service Home Page.

  8. Generate the client code:

    • For the J2SE environment, generate stubs (client proxies) for a J2SE Web service client by running the WebServicesAssembler tool with the genProxy command. For more information on generating and assembling client-side code for a J2SE Web service, see Chapter 14, "Assembling a J2SE Web Service Client".

    • For the J2EE environment, generate a service endpoint interface and a JAX-RPC mapping file for a J2EE Web service client by running the WebServicesAssembler tool with the genInterface command. For more information on generating and assembling client-side code for a J2EE Web service, see Chapter 13, "Assembling a J2EE Web Service Client".

    For example, the following command generates client proxies (stubs) that can be used for a J2SE client:

    java -jar wsa.jar -genProxy 
                    -wsdl http://localhost:8888/doclit_topdown/doclit_topdown?WSDL
                    -unwrapParameters false  
                    -output build/src/client 
                    -packageName oracle.demo.topdowndoclit.stubs 
                    -mappingFileName type-mapping.xml
    
    

    In this example, doclit_topdown is an application name for the generated Web service.

    At a minimum, specify the name of the WSDL and the name of the output directory. The WebServiceAssembler tool generates a stub. A client application uses the stub to invoke operations on a remote service. For more information on the required and optional arguments to genProxy, see "genProxy".

  9. Compile and run the client.

    List the appropriate JARs on the classpath before compiling the client. Table A-2, "Classpath Components for a Client Using a Client-Side Proxy" lists all of the JAR files that can possibly be used on the client classpath. As an alternative to listing individual JARs, you can include the client-side JAR, wsclient_extended.jar on the client classpath. This JAR file contains all the classes necessary to compile and run a Web service client. The classes are from the individual JAR files listed in Table A-2. See "Setting the Web Service Proxy Client Classpath" for more information on wsclient_extended.jar and the client classpath.

Generating a Web Service Top Down with Ant Tasks

The current release supports Ant tasks for Web services development. The following examples show how the WebServiceAssembler commands in the preceding examples can be rewritten as Ant tasks.

In these examples, doclit_topdown is an application name for the generated Web service.

For more information on Ant tasks for WebServiceAssembler commands, see "WebServicesAssembler Commands".

For the genInterface command, here is an example Ant task:

<oracle:genInterface wsdl="wsdl/LoggingFacility.wsdl" 
              output= "build/src/service"   
              packageName= "oracle.demo.topdowndoclit.service" 
              mappingFileName="type-mapping.xml" 
              dataBinding="true" 
              unwrapParameters="false"
/oracle:genInterface>

For the topDownAssemble command, here is an example Ant task:

<oracle:topDownAssemble appName="doclit_topdown"
         wsdl="./wsdl/LoggingFacility.wsdl"
         unwrapParameters="false"
         input="build/classes/service "
         output="build"
         ear="dist/doclit_topdown.ear"
         mappingFileName="type-mapping.xml"
         packageName="oracle.demo.topdowndoclit.service"
         fetchWsdlImports="true"
         >
            <oracle:portType
               className="oracle.demo.topdowndoclit.service.DocLitLoggerImpl"
            </oracle:portType>
  />

For the genProxy command, here is an example Ant task:

<oracle:genProxy
    wsdl="http://localhost:8888/doclit_topdown/doclit_topdown?WSDL"
    unwrapParameters="false"
    output="build/src/client"
    packageName="oracle.demo.topdowndoclit.stubs"
    mappingFileName="type-mapping.xml"
/>

Limitations

See "Assembling Web Services from a WSDL".

Additional Information

For more information on: