Create a Web service from an enterprise bean (EJB)

 

Prerequisites:

The Web Service wizard assists you in creating a new Web service, configuring it for deployment, and deploying the Web service to a server. Once your Web service is deployed, the wizard assists you in generating the client proxy and sample application to test the Web service. When you have completed testing, you can publish your Web service to a UDDI Business Registry using the Export wizard.

For more information on EJB application development, refer to EJB tools.

Note: Rational Developer products support enterprise bean Web service creation from stateless session enterprise beans.

The Web service you are creating acts as a client to the enterprise bean. The enterprise bean must be deployed before launching the Web service wizard.

To create a Web service from an enterprise bean:

  1. Switch to the J2EE perspective (Window > Open Perspective > J2EE).

  2. In the Project Explorer view, select the Web project in which you want to create the Web service.

    Alternatively, you can launch the Web Service wizard from the J2EE perspective by selecting the enterprise bean from which you will create your Web service and following the remaining steps.

  3. Click File > New > Other. Select Web Services in order to display the various Web service wizards. Select the Web Service wizard. Click Next.

  4. Web Services page: select EJB Web service from the Web service type drop down list. You can optionally choose to do the following:

    • Start the Web service in a Web project - if you do not select this option you will have to manually start the Web service. You must select this option to enable the other options on this page.

    • Launch the Web Services Explorer to publish your Web service to a UDDI registry.

    • Generate a Java bean client proxy to the Web service. The Java bean client proxy that is generated provides a remote procedure call interface to the Web service.

    • Test the Web service - this allows you to test the Web service in the Web Service Explorer before a proxy is generated.

    • Send the Web service traffic through the TCP/IP Monitor, which allows you to watch the SOAP traffic generated by the Web service and to test this traffic for WS-I compliance.

  5. Service Deployment Configuration page: specify the server and client deployment settings.

    1. Click Edit and select the IBM SOAP run-time environment and select the server on which you want to run your Web service and Web service client. If you want to use the IBM WebSphere run-time environment or the Apache Axis 1.0 run-time environment, refer to the appropriate task.

    2. Select the EJB project, router project, and EAR for your Web service. The wizard will create these for you if they do not already exist.

    3. Select the type and name of project in which you want the Web service client created. If you enter the name of an existing project, the project type field must match that of the existing project. If you enter a name of a project that does not already exist, the wizard will create the project for you. Note that the only project type supported for Axis and SOAP run-time clients is a Web project. If you want the client to be created in a Java, EJB, or Application Client project, select the WebSphere run-time environment for your client.

    4. Select an existing EAR or enter a unique name to associate the Web service client with a different EAR than the Web service EAR. Note: Selecting different EARs for the Web service and Web service client can reduce the chance of encountering run time errors, but will use more system resources.

  6. Web Service EJB Configuration panel: click Browse EJB Beans. This allows you to browse the J2EE perspective for an enterprise bean.

  7. In the Browse Enterprise Beans dialog box select the Enterprise Application project that contains your enterprise bean and the EJB project. Then select your enterprise bean and EJB project. Click OK. The EJB configuration, such as JNDI provider URL, JNDI initial context factory, EJB JNDI name, EJB home interface class name, and EJB remote interface path name is automatically completed. Click Next.

    Note: The Browse Enterprise Beans dialog box displays only the Enterprise Application projects that contain the selected Web project. The dialog can only be used to select those enterprise beans and EJB Projects that are contained in the same Enterprise Application project as the Web project.

  8. Web Service Java Bean Identity panel: specify the Web service URI, and the scope. You can optionally select to use static methods and secure SOAP. You can modify the document and folder names listed on this page, or accept the default names.

  9. Web Service Java Bean Methods panel: select the methods to expose and select the input and output encoding styles. If you want to review the the Java to XML mappings, select Show Server Type Mappings.

  10. Web Service Java to XML Mappings page: if you have chosen to review the mappings, you can see them here. Alternately, customize your mappings by selecting Edit and use a customized mapping.

  11. Web Service Test page: If you selected to test the Web service, select the test facility for the generated Web service, and click Launch. This will open the Web service in the Web Services Explorer. Select the operation you want to test, enter the required information, and click Go. The result will display in the Status pane. When you have tested the Web service, close the browser window and click Next.

  12. Web Service Binding Proxy Generation panel: if you have selected to generate a proxy, select the binding and proxy options.

  13. Web Service Client Test page: Use this page to select the following options:

    • Select your test facility. You can test the generated proxy in the Universal Test Client or the Web Service Explorer, or you can generate a sample Web service JSP.

    • If you selected to test the proxy through a JSP, you can select the folder where the JSP will be located, and you can select the methods that will be included in the JSP.

    • Select Run test on server to start the server for you automatically.

  14. Web Service Publication page: Select whether or not you want to publish this Web service to a UDDI registry. Click Finish.

After the Web service has been created, the following may occur depending on the options you selected:

Important: If your methods contain types, not supported by the sample, such as arrays, indexed properties, and collections, the methods will be omitted from the sample and you will receive a warning message.

Once you have created your Web service from an enterprise bean, you may test the methods of your Web service, using the Universal Test Client, and then publish your Web service to a UDDI Business Registry. For more information on testing and publishing your applications, refer to the Server tools documentation.

For more information on EJBs, refer to the EJB application development documentation.

 

Related Concepts

Tools for Web services development
Web services development
Web services run-time environments

Related Tasks
Developing Web services
Using the Web Services Explorer

Related Reference
Deployment properties
Mapping properties
WSDL documents